且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Selenium WebDriver检查按钮是否可单击

更新时间:2023-11-30 17:33:34

只需编写以下方法,并在需要检查元素是否可单击时调用它.还传递必需的参数.

Just write the below method and call it whenever you want to check whether element is clickable or not. Pass the required arguments also.

public static boolean isClickable(WebElement el, WebDriver driver) 
    {
        try{
            WebDriverWait wait = new WebDriverWait(driver, 6);
            wait.until(ExpectedConditions.elementToBeClickable(el));
            return true;
        }
        catch (Exception e){
            return false;
        }
    }