0

I'm trying to locate a web element that have two child nodes as:

<div _ngcontent-c2="" class=" " title="Twelve (Start date is 31| 0 user)" xpath="1"></div>
<div _ngcontent-c2="" class=" " title="Twelve (Start date is 31| 0 user)" xpath="2"></div>

I tried //div[contains(@title,'Twelve (Start date is 31| 0 user)')][1] to get the first element but didn't work for me.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Adham Salem
  • 13
  • 1
  • 5

2 Answers2

0

You can try with CSS:

div[xpath='1']

div[xpath='2']
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
0

xpath="1"

xpath="1" attribute is the reference of xpath v1.0

xpath="2"

xpath="2" attribute is the reference of xpath v2.0

For the record Selenium supports XPath v1.0 only.

A bit more of the outerHTML including the parent tag would have helped us to construct a more canonical answer. Moreover the information about the Language Binding you are using is also missing. However to locate the first element you need to induce WebDriverWait for the desired visibilityOfElementLocated() and you can use the following can use the following xpath:

  • Java:

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@title,'Start date is 31') and @xpath='1']")));
    
  • Python:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@title,'Start date is 31') and @xpath='1']")))
    

Here you can find a detailed discussion on What are the differences between versions of XPath (1.0, 2.0, 3.1)

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352