samedi 22 juillet 2017

Selenium Python find element on few pages

In my application i have a table with users. In my test i want to add new user and then check is the user is added, but the table can have more than 1 page, and when i'm looking that element i can find it just on first page. Here is my code:

def test_new_user(driver, username='jared144'):
login(driver, username="Admin", password="Password")
# add new user
add_new_user(driver, username)
#check if the new user added
assert is_element_present(driver, By.LINK_TEXT, "%s" % username)

def add_new_user(driver, username):
driver.find_element_by_css_selector("[id=btnAdd]").click()
driver.find_element_by_css_selector("[id=systemUser_employeeName_empName]").send_keys("Adelia Foxy")
driver.find_element_by_css_selector("[id=systemUser_userName]").send_keys("%s" % username)
driver.find_element_by_css_selector("[id=systemUser_password]").send_keys("12345678")
driver.find_element_by_css_selector("[id=systemUser_confirmPassword]").send_keys("12345678")
driver.find_element_by_css_selector("[id=btnSave]").click()

def is_element_present(driver, how, what):
try:
    driver.find_element(by=how, value=what)
except NoSuchElementException as e:
    return False
return True

def login(driver, username, password):
driver.get("http://ift.tt/2tpseYo")
driver.find_element_by_css_selector("[name=txtUsername]").send_keys(username)
driver.find_element_by_css_selector("[name=txtPassword]").send_keys(password)
driver.find_element_by_css_selector("[name=Submit]").click()
driver.find_element_by_css_selector("[id=menu_admin_viewAdminModule]").click()

I have an idea how to do that, something like:

if NoSuchElementException
   find_element_by().click() #click second page

But i don't know how to realize this

Aucun commentaire:

Enregistrer un commentaire