You should be able to select elements with multiple classes like so:
//div[contains(@class, "pro-tease") and contains(@class, "even")]
This will select div
s that have both pro-tease
and even
class, e.g.
<div class="pro-tease something even">...</div>
<div class="irrelevant pro-tease foo even">...</div>
It will not, however, select divs that have only one of the two specified classes. If you want to select an element that has either one class or the other, try this:
//div[contains(@class, "pro-tease") or contains(@class, "even")]
Now, if you had four divs:
<div class="pro-tease irrelevant">...</div>
<div class="even irrelevant">...</div>
<div class="not specified">...</div>
<div class="pro-tease even">...</div>
1, 2, 4 would be selected, as they all contain either pro-tease
or even
.
By this point, you probably noticed that contains()
does exactly what it says: checks if the class name contains the specified argument. Hence, if you join two contains()
with and
, you are basically saying "give me elements that contain this class and also this one", whereas with or
it's more like "give me elements that have either this class, or this class".
By the way, you can test your queries in Chrome developer mode (Ctrl+Shift+I) by searching the elements (Ctrl + F). If your query does not work in the browser, it will probably not work in elsewhere either.