2

How to locate this element?

enter image description here

<div _ngcontent-ysj-c5>
    <div _ngcontent-ysj-c5 class="list-items unselected"> == $0
        <!---->
        " Installation "
    </div>
</div>

i have tried

driver.find_elements_by_xpath("//[contains(text(),' Installation ')]"). 

&

driver.find_element_by_xpath("//*[text()=' Installation ']").click();

but it doesn't work.

2
  • you should give more information about the path Commented Jul 30, 2020 at 8:44
  • include your code in your question, I've tried to do this but it is currently being checked. Commented Jul 30, 2020 at 8:57

2 Answers 2

1

How about this:

driver.find_elements_by_xpath("//*[contains(.,'Installation')]")

or

driver.find_element_by_xpath("//*[.=' Installation ']")

=)

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

2 Comments

@jaop Helpful answer but why dropping the tagName <div> from the locator?
it can be div instead of *, to locate div element that has value ' Installation '. In case we use *, all elements that have value ' Installation ' will match. in this case, the first matching element will be selected.
1

Try below locators:

driver.find_elements_by_xpath("//div[text()='Installation']")

or

driver.find_elements_by_xpath("//div[normalize-space()='Installation']")

2 Comments

@Shrini You were almost there, there is a syntax error in the xpath, an additional ) after Installation'
@DebanjanB thanks for that I just corrected it. It was a typo.

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.