0

In my application, I have a table with users but the table can have more than 1 page with users. I want to get a list with all users in all pages with Selenium Webdriver Python. I have test function which goes to the first page, gets a list with all users then goes to the second page gets a list of users and until the pages no longer exist:

def test_users1(driver):
    login(driver, username="Admin", password="Password")
    while True:
         try:
            #gets list of elements
            userslist = driver.find_elements_by_css_selector(".even .odd")
            #goes to second page, third...etc.
            for i in range(1, 50):
                driver.find_element_by_link_text("%s" % i).click()
         except NoSuchElementException:
            break
         return (userslist)

I need to return split list with all users from all pages from my loop

1
  • add userslist += driver.find_element_by_link_text("%s" % i).click() if driver.find_element_by_link_text("%s" % i).click() returns the list of user Commented Jul 29, 2017 at 18:04

3 Answers 3

0

Try use list extend method

def test_users1(driver):
    login(driver, username="Admin", password="Password")
    userslist = []
    while True:
        try:
            #gets list of elements
            userslist.extend(driver.find_elements_by_css_selector(".even .odd"))
            #goes to second page, third...etc.
            for i in range(1, 50):
                driver.find_element_by_link_text("%s" % i).click()
                userslist.extend(driver.find_elements_by_css_selector(".even .odd"))
                # Add new line here ^^^^
        except NoSuchElementException:
            break
    return (userslist)
Sign up to request clarification or add additional context in comments.

2 Comments

may be this: assert (len(userslist) == YOUINT), "Wrong users list"
link I don't know why but it returns me Sized type not int
0
def users1(driver):
userslist = []
while True:
    try:
        #gets list of elements
        userslist.extend(driver.find_elements_by_css_selector("tbody tr"))
        #goes to second page, third...etc.
        for i in range(1, 50):
            driver.find_element_by_link_text("%s" % i).click()
    except NoSuchElementException:
        break
return len(userslist)

def test_users1(driver):
login(driver, username="Admin", password="Password")
assert users1(driver) == 50

Comments

0
def users1(driver):
    userslist = []
    while True:
        try:
            #gets list of elements
            userslist.extend(driver.find_elements_by_css_selector(".even .odd"))
            #goes to second page, third...etc.
            for i in range(1, 50):
                driver.find_element_by_link_text("%s" % i).click()
        except NoSuchElementException:
            break
    return userslist


def test_users1(driver):
    login(driver, username="Admin", password="Password")
    users = users1(driver)
    assert len(users) == 63

5 Comments

@Bear Brown I found decision, thank you so much for help. stackoverflow.com/a/45394732/6939940
I'm glad to help a little.
@Bear Brown I'm sorry I thought it works but it doesn't, the algorithm is right but the lists don't splitting, always return result 50 which is from just 1 page
I add a new line to your algorithm try it: stackoverflow.com/questions/45392369/…
I'm glad to help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.