0

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. how to can i do that?

sorry for grammatical errors, i'm not english🥲

3 Answers 3

1

I'm not so sure about JaSON's solutions, neither of them doesn't look like a valid xpath to me...

try this, it should work for you:

//div[div[contains(text(), 'Example_String')]]
Sign up to request clarification or add additional context in comments.

Comments

1

Try this one:

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

for child div or

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

for descendant div

Comments

0

If the child div is an immediate child of parent 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')]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.