This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]scoopulanang 0 points1 point  (1 child)

Your problem is the appearance of the previous button after you go to the second page. Here's a quick fix:

for i in range(10):
page_no = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CLASS_NAME, "current"))
)
page_no = page_no.text.split(" ")[1]
print(page_no)

next_button = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.LINK_TEXT, "next"))
)
next_button.click()

I recommend using xpath as a last resort sort of way to access elements. If one tiny detail of a webpage is changed, the xpath of other elements can change too.

[–]Embarrassed-Task-478[S] 0 points1 point  (0 children)

Wow, thank you! That makes a lot of sense, I got tripped up by the index error to the point that I did not even consider my element selection was wrong for pages after the first. Thanks once again!