-1

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 pages to collect the links. I have used this which doesn't work;

 try:
     # this is navigate to next page
     driver.find_element_by_xpath('//div[@id="searchResultsSection"]/ul/li[12]').click()
     time.sleep(1)
 except NoSuchElementException:
     break

The syntax behind the next button can be seen below;

<a href="" onclick="PageRequest('2', event)" class="xh-highlight">&gt;</a>

Does anybody no how to write the code to click the next button?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Chris
  • 33
  • 6

3 Answers3

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()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

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();
Developer Guy
  • 2,318
  • 6
  • 19
  • 37
Azalkor
  • 87
  • 7
0

You can try to use below line to click Next button

driver.find_element_by_link_text(">").click()
Andersson
  • 51,635
  • 17
  • 77
  • 129