Skip to content Skip to sidebar Skip to footer

Python Selenium - How To Loop To The Last
  • Element In A Site
  • I have created a python selenium script that should navigate through a website and collect people profiles (https://www.shearman.com/people). The program won't loop through the pag

    Solution 1:

    If you look at the HTML of the element with image as >, it is the <a> tag within the last <li> tag of the <ul> tag. So to invoke click() on it you can use the following code block :

    driver.find_element_by_xpath("//ul[@class='results-pagination']/li[last()]/a").click()
    

    Solution 2:

    You can try to use below line to click Next button

    driver.find_element_by_link_text(">").click()
    

    Solution 3:

    you can do it yourself :

    • ctrl+shift+i
    • right click on the next button -> inspect
    • right click on the next button code -> copy -> copy selector

    then you store the button in a WebElement nextButton then

    nextButton.click();
    

    Post a Comment for "Python Selenium - How To Loop To The Last
  • Element In A Site"