Skip to content
Advertisement

Python Selenium – Clicking pages without next button

enter image description hereI would like to get info from multiple pages by clicking through them. The problem is there is not next button and even though the page link contains a number for counting through , as you can see in the image below.

Can anyone help on how to solve this?

Advertisement

Answer

i=2
While True:
    try:
        #some wait
        driver.find_element_by_xpath("//a[@class='btn btn-primary spacebutton' and .='{}']".format(str(i+1))).click()
        i++
    except:
        break

Just loop through the a tags and click them based on their text.

Advertisement