I am trying to press the next button on this webpage until there are no pages left, but it seems my code is not able to find the next button as the script stops running immediately.
I know there are a lot of similar questions, but I have not been able to solve the issue by looking at those questions. Really appreciate the help!
CodePudding user response:
It is evident that there are 100 pages. So why not just iterate through that?
Change
while True:
try:
driver.find_element(By.XPATH, '//*@id="content"]/div/article[3]/div[11]/ul[1]/li[13]/a').click()
print("Navigating to next page")
except NoSuchElementException:
print('Last page reached')
break
[Do something]
to
for i in range(100):
driver.get('https://doffin.no/Notice?pageNumber=' str(i 1) '&pageSize=10')
[Do something]