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)