Check if element is clickable in Selenium Java

前端 未结 7 2051
南旧
南旧 2020-11-29 08:19

I\'m new to Selenium and need to check if element is clickable in Selenium Java, since element.click() passes both on

7条回答
  •  余生分开走
    2020-11-29 08:50

    the class attribute contains disabled when the element is not clickable.

    WebElement webElement = driver.findElement(By.id("elementId"));
    if(!webElement.getAttribute("class").contains("disabled")){
        webElement.click();
    }
    

提交回复
热议问题