Python Selenium find specific class and ignore other classes

Viewed 192

I have some divs with multiple classes as follows

<div class="a"></div>
<div class="a b"></div>
<div class="a c"></div>

Using Selenium I am able to find all a classes however I want to ignore those that have a b class. How would I achieve this?

driver.find_elements_by_css_selector('.a')
1 Answers

I was able to get this working by using XPath.

driver.find_elements_by_xpath("//div[contains(@class, 'a') and not(contains(@class, 'c'))]/div")
Related