Home > Net >  How to find element with "== $0" after end tag in html using Xpath, css or any other locat
How to find element with "== $0" after end tag in html using Xpath, css or any other locat

Time:12-04

the html tag

<div ><div>Bengaluru, Karnataka</div></div>

Consider the above example for reference.

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

driver.find_element(By.XPATH,'//div[@]').text.strip()

CodePudding user response:

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]]

CodePudding user response:

You can use this:

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

Output:

Bengaluru, Karnataka
  • Related