I would like to write a code that would make Python scrape some data on a page, then click on the "next" button at the bottom of the page, scrape some data on the second page, click on the "next" button, etc. until the last page, where clicking on "Next" is no longer possible (because there is no "next").
I would like to make the code as general as possible and not specify beforehand the number of clicks to be done. Following this question (How can I make Selenium click through a variable number of "next" buttons?), I have the code below. Python does not report any error, but the program stops after the first iteration (after the first click on the "next").
What am I missing here? Many thanks!
driver = webdriver.Firefox()
driver.get("http://www.mywebsite_example.com")
try:
wait = WebDriverWait(driver, 100)
wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'reviews_pagination_link_nav')))
driver.find_element_by_class_name("reviews_pagination_link_nav").click()
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'reviews_pagination_link_nav')))
while EC.element_to_be_clickable((By.CLASS_NAME,'reviews_pagination_link_nav')):
driver.find_element_by_class_name("reviews_pagination_link_nav").click()
if not driver.find_element_by_class_name("reviews_pagination_link_nav"):
break
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'reviews_pagination_link_nav')))
finally:
driver.quit()