Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python 3.x - Can't seem to find an XPath with a value that contains double quotes

I've read through the forums and apparently almost nobody has issues to find XPaths with values with double quotes, most posts I found talked about finding Xpaths to elements with values that had both single quotes and double quotes, so I decided to ask this question, I apologize if this is already answered elsewhere.

Anyway, the element I wanted to find goes more or less like this:

<a class="product" title="REALIZE  "WHY  NO.T"" width="454" height="423" alt="" id="">
    </a>

I tried changing the XPath several times without success, using Selenium Webdriver

'//a[@title="REALIZE "WHY  NO.T""]' 

'//a[@title="REALIZE "WHY  NO.T""]'

"//a[@title="REALIZE "WHY  NO.T""]"

These are a few of the ones I tried, there are a few more but I didn't save all the ones I tried

I feel like it might be a matter of me missing something terribly basic, but I've been looking for the answer for hours without success

question from:https://stackoverflow.com/questions/65713388/cant-seem-to-find-an-xpath-with-a-value-that-contains-double-quotes

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

1 Reply

0 votes
by (71.8m points)
//*[@title='REALIZE "WHY NO.T"']

You have to wrap content with single quotes, the python code will be ( escaping the single quotes

driver.find_element_by_xpath('//*[@title='REALIZE "WHY NO.T"']')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...