E SV
E SV

Reputation: 133

How can I differ between elements that have some same and some different classes in Selenium?

So I have two elements that I am trying to describe in selenium with classes: element1 has class1 and class2, and element2 has class1, class2, class3. I describe element1 like this:

element1 = driver.find_elements_by_css_selector(.class1.class2)[0]

But when my script runs, element1 somehow includes element2. How can I desribe these elements so that they would differ? (xpath is not applicable because these are calendar cells and I need to reach all of them without writing a description for each of them).

Upvotes: 0

Views: 49

Answers (1)

Guy
Guy

Reputation: 50919

You can use not(.class3) to locate an element without that class

element1 = driver.find_elements_by_css_selector('.class1.class2:not(.class3)')[0]

Upvotes: 3

Related Questions