0

I am trying to use a label to identify the next page button on the web search page, I currently have the code

next_page = driver.find_element_by_xpath(//label[contains(text(),'Page'+str(page_no+1))]//ancestor:div//input)

I got to this stage through this link here: Unable to locate element for LABEL with the XPath expression

I am working in Spyder and it says that this is invalid syntax and won't run the code. I'm not sure why as it seems correct according to the previous answer I followed.

Can someone point out what is wrong with this to me please or identify an alternative code I can use to find element by a label?

Seanny123
  • 8,776
  • 13
  • 68
  • 124
Sam
  • 1
  • 1
  • I just want to add page_no is defined in a for loop as I want to go through a range of 10 pages. – Sam Jan 24 '21 at 23:34
  • Hi Sam, welcome to SO! Can you please post the error message you get? – demokritos Jan 25 '21 at 00:51
  • Hi thanks for replying! I'm working on Spyder and am unable to run the script as it says 'invalid syntax' - this is addressed to the line in question. – Sam Jan 25 '21 at 14:25

1 Answers1

0

I solved this by finding a clickable point for the 'Next page' button, which appeared as a title. I then used this in the code as follows:

driver.find_element_by_xpath('//*[@title="Next page"]').click()
Sam
  • 1
  • 1