-1

Suppose I have an HTML that looks like this:

<div class="first second">
    Right!
</div>
<div class="first second third fourth">
    Wrong!
</div>
<div class="first second">
    Right!
</div>

If I try to locate the first and third div, using css:

driver.find_elements_by_class_name("first, second")

Instead of getting 2 elements in my list, I get all the three divs because the second one actually contains those classes and some others... How can I restrict it, to locate only the <div>s with:

class = "first second"
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
James Deen
  • 43
  • 6

2 Answers2

1
div[class = 'first second']

should work. Cause it is a exact match.

use it with CSS_SELECTOR

driver.find_elements(By.CSS_SELECTOR , "div[class = 'first second']")
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
1

You can use this if you need to get them via xpath:

driver.find_elements_by_xpath(".//div[@class='first second']")
itronic1990
  • 1,231
  • 2
  • 4
  • 18