Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

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?

question from:https://stackoverflow.com/questions/65877150/cannot-find-element-by-xpath-with-webdriver-for-a-label-on-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...