1

I have following elements on the page:

<span class="card-body">
    <span>No tickets</span>
    <h5 class="card-title">..</h5>
    <p class="card-text card-text-top">..</p>
    <p class="card-text">..</p>
</span>

There are several the same card-body elements in the DOM, however, I would like to identify the first one that does not contain <span>No tickets</span> child element.

What is the most correct locator which I should use, while working with selenium and C#?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
srulom
  • 93
  • 3

2 Answers2

0

To identify the first element that does not have a decendent <span>No tickets</span> element you can use the following xpath based locator strategy:

//span[@class='card-body'][not(.//span[text()='No tickets'])]

Your effective line of code will be:

driver.FindElement(By.XPath("//span[@class='card-body'][not(.//span[text()='No tickets'])]"))

Snapshot of the example:

ticket

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0
//span[@class='card-body'][not(span[text()='No tickets'])]

Gets the span with class card-body that does not have span with text "No tickets".

K. B.
  • 3,342
  • 3
  • 19
  • 32