简体   繁体   中英

Cannot find element by xpath with webdriver for a label on Python

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?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM