user3364652 user3364652 - 25 days ago 7
Java Question

Selenium - how to find elements by attribute with any value in Java?

I know this way I can find element by attribute and value:

webDriver.findElements(By.xpath("//element[@someAttribute='someValue']"))


How can I find all elements that has the attribute
someAttribute
no matter what the value is?

Thanks

Answer

Just use //element[@someAttribute] for your XPath expression.