Find element by attribute
You can easily get this task accomplished with CSS.
The formula is:
element[attribute='attribute-value']
So if you have,
<a href="mysite.com"></a>
You can find it using:
By.cssSelector("a[href='mysite.com']");
this works using any attribute possible.
This page here gives good information on how to formulate effective css selectors, and matching their attributes: http://ddavison.io/css/2014/02/18/effective-css-selectors.html
I do not understand your requirement:
Assuming XPath is not an option ...
If this was just an incorrect assumption on your part, then XPath is the perfect option!
webDriver.findElements(By.xpath("//element[@attribute='value']"))
Of course you need to replace element
, attribute
, and value
with your actual names. You can also find "any element" by using the wildcard:
webDriver.findElements(By.xpath("//*[@attribute='value']"))