From 7f9e6590189227d6bb80b882a9e78a0d35f7c537 Mon Sep 17 00:00:00 2001 From: Nico Schedel Date: Fri, 17 Jan 2020 12:47:29 +0100 Subject: [PATCH] TT#70901 selenium: add scroll_to_element add function scroll to element, since this function is easier to remember and use than anything in javascript. replaced every javascript scroll call with this function. Change-Id: Ie9bb3b258f35da96d00a111d1be0db7fe1aa53f7 --- t/selenium/functions/Collections.py | 25 ++++++++----------------- t/selenium/functions/Functions.py | 8 ++++++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/t/selenium/functions/Collections.py b/t/selenium/functions/Collections.py index 65a28036..dfd1f029 100644 --- a/t/selenium/functions/Collections.py +++ b/t/selenium/functions/Collections.py @@ -54,19 +54,16 @@ def create_customer(driver, name=None): driver.find_element_by_link_text('Create Customer').click() WebDriverWait(driver, 10).until(EC.element_to_be_clickable(( By.XPATH, '//*[@id="contactidtable"]//tr[1]//td/input'))) - driver.execute_script( - "arguments[0].scrollIntoView();", driver.find_element_by_xpath( - '//*[@id="contactidtable"]//tr[1]//td/input')) + Functions.scroll_to_element( + driver, '//*[@id="contactidtable"]//tr[1]//td/input') driver.find_element_by_xpath( '//*[@id="contactidtable"]//tr[1]//td/input').click() - driver.execute_script( - "arguments[0].scrollIntoView();", driver.find_element_by_xpath( - '//*[@id="billing_profileidtable"]//tr[1]//td/input')) + Functions.scroll_to_element( + driver, '//*[@id="billing_profileidtable"]//tr[1]//td/input') driver.find_element_by_xpath( '//*[@id="billing_profileidtable"]//tr[1]//td/input').click() - driver.execute_script( - "arguments[0].scrollIntoView();", driver.find_element_by_xpath( - '//*[@id="external_id"]')) + Functions.scroll_to_element( + driver, '//*[@id="external_id"]') Functions.fill_element( driver, '//*[@id="external_id"]', name) driver.find_element_by_xpath('//*[@id="save"]').click() @@ -120,10 +117,7 @@ def create_subscriber(driver, customername, domainname): ) hoverclick.perform() driver.find_element_by_link_text('Expand Groups').click() - driver.execute_script( - 'arguments[0].scrollIntoView();', - driver.find_element_by_link_text('Subscribers') - ) + Functions.scroll_to_element(driver, 'Subscribers') driver.find_element_by_link_text("Create Subscriber").click() WebDriverWait(driver, 10).until(EC.element_to_be_clickable( (By.XPATH, '//*[@id="domainidtable_paginate"]/a[4]'))) @@ -175,10 +169,7 @@ def delete_subscriber(driver, customername): ) hoverclick.perform() driver.find_element_by_link_text('Expand Groups').click() - driver.execute_script( - 'arguments[0].scrollIntoView();', - driver.find_element_by_link_text('Subscribers') - ) + Functions.scroll_to_element(driver, 'Subscribers') WebDriverWait(driver, 1) hoverclick = ActionChains(driver) hoverclick.move_to_element(driver.find_element_by_xpath( diff --git a/t/selenium/functions/Functions.py b/t/selenium/functions/Functions.py index e6aeb275..1aa9173b 100644 --- a/t/selenium/functions/Functions.py +++ b/t/selenium/functions/Functions.py @@ -13,3 +13,11 @@ def fill_element(driver, element, text, pathtype=By.XPATH): elem.send_keys(Keys.CONTROL + "a") elem.send_keys(Keys.DELETE) elem.send_keys(text) + + +def scroll_to_element(driver, element): + if element[:2] == "//": + webelem = driver.find_element_by_xpath(element) + else: + webelem = driver.find_element_by_link_text(element) + driver.execute_script("arguments[0].scrollIntoView();", webelem)