18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Select by single class element that has multiple classes
I'm working with Sahi through the Twist testing IDE, so I'm using the Java driver. I've been surprised that if I try to select an element with multiple classes on it by a single class that it doesn't select anything. Here is an example of what I mean.
HTML snippet:
Java snippet:
In the above situation the try1 and try2 variables are false but the thingThatWorks is true. Am I missing something? Is there a way to select an element by a single class name when it has multiple? The workaround I have found is to use the XPath selector and use xpath something like //div[contains(*at*class, "one")] but I'd rather not use xpath.
ps. the *at* is supposed to be an at symbol but the forum software wouldn't let me use that symbol because it thinks i am trying to post an email address.
HTML snippet:
<div class="one two">Text</div>
Java snippet:
boolean try1 = browser.byClassName("one").exists();
boolean try2 = browser.div("one").exists();
boolean thingThatWorks = browser.div("one two").exists();
In the above situation the try1 and try2 variables are false but the thingThatWorks is true. Am I missing something? Is there a way to select an element by a single class name when it has multiple? The workaround I have found is to use the XPath selector and use xpath something like //div[contains(*at*class, "one")] but I'd rather not use xpath.
ps. the *at* is supposed to be an at symbol but the forum software wouldn't let me use that symbol because it thinks i am trying to post an email address.
Comments
Use
browser.div("/one/").exists(); // a js regex match
for matching using only one of the css classNames.
Regards,
Narayan