1

I want to access elements of all balises that find like this : <div class='xxxx' the text >

I did as this with Xpath:

textSearch = 'the text'
hometeam = driver.find_elements(By.XPATH,"//div[@class='xxxx'] and //div[contains(text(),'"+ textSearch +"')]")

But this not works and casting this exception : TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.

How do ?

2
  • //div[@class='xxxx' and contains(text(), 'justin')] Commented Oct 15, 2020 at 15:13
  • Your XPath returns boolean value while Selenium supports WebElement only Commented Oct 15, 2020 at 15:17

1 Answer 1

3

Combine the conditions within the [...]

E.g., //div[@class='xxxx' and contains(text(), 'justin')].

Demo here

Sign up to request clarification or add additional context in comments.

2 Comments

Small addition: an alternative to "and" can also be attaching one predicate to another //div[@class='xxxx'][contains(text(), 'justin')]
I did not know that. Thanks, @AlexandraDudkina.

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.