Skip to main content
1 of 3
Alexey R.
  • 11.6k
  • 5
  • 20
  • 39

This should work for you.

List<WebElement> enabledButtons = driver.findElements(By.xpath("//button[not(@disabled)]"));
if(!enabledButtons.isEmpty()){
    enabledButtons.get(0).click();
}

Explanation

Your disabled buttons have "disabled" attribute. So you need the xpath that would query all the buttons which do not have that attribute (//button[not(@disabled)]).

Now you use findElements method to look up all the elements meeting the xpath criteria. Check if the list is not empty (you have at least one enabled button). And process the very first item.

Alexey R.
  • 11.6k
  • 5
  • 20
  • 39