Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find element with "== $0" after end tag in html using Xpath, css or any other locators in Selenium Python?

the html tag

<div class=""><div>Bengaluru, Karnataka</div></div>

Consider the above example for reference.

I tried the following code but it doesn’t work!!!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

driver.find_element(By.XPATH,’//div[@class=""]’).text.strip()

>Solution :

You can not filter by that "==$0"

But you can use this xpath, which will return to you the element with following requirements:

  • It is a "div"
  • That "div" contains an attribute "class"
  • That "class" attribute has a length of 0 chars

This is the xpath:

//div[@class[string-length()=0]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading