简体   繁体   English

Xpath:如何使用 div 中的元素查找 div

[英]Xpath: how to find a div using the elements in the div

i writed this line of code (i know it isn't correct)我写了这行代码(我知道它不正确)

driver.find_element(By.XPATH, '//div[contains(div[contains(string(),"Example_String"))]').click()

i need to find the div that contains a div that contains a string .我需要找到包含包含字符串的 div 的 div how to can i do that?我该怎么做?

sorry for grammatical errors, i'm not english🥲抱歉语法错误,我不是英语🥲

Try this one:试试这个:

'//div[contains(div,"Example_String")]

for child div or对于div

'//div[contains(.//div,"Example_String")]

for descendant div对于后代div

I'm not so sure about JaSON's solutions, neither of them doesn't look like a valid xpath to me...我不太确定 JaSON 的解决方案,它们对我来说都不是有效的 xpath ......

try this, it should work for you:试试这个,它应该适合你:

//div[div[contains(text(), 'Example_String')]]

If the child div is an immediate child of parent div - //div/div[contains(text(),'SOME_TEXT')]如果子 div 是父 div 的直接子级 - //div/div[contains(text(),'SOME_TEXT')]

If the child div is somewhere far inside the parent div - //div//div[contains(text(),'SOME_TEXT')] OR //div[contains(text(),'SOME_TEXT')]如果子 div 位于父 div 内部的某个地方 - //div//div[contains(text(),'SOME_TEXT')]//div[contains(text(),'SOME_TEXT')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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