org.openqa.selenium.support.ui.ExpectedConditions有些方法似乎不可靠,如何处理呢?

时间:2016-10-18 02:56:51

标签: java selenium

以下是我的代码:

@FindBy(id = 'save')
private WebElement saveBtn;

public void clickSaveBtn() {
    WebDriverWait waiter = new WebDriverWait(driver, 5, 200);
    waiter.until(ExpectedConditions.presenceOfElementLocated(By.id("save")));
    waiter.until(ExpectedConditions.elementToBeClickable(By.id("save")));
    saveBtn.click();
}

如果像上面这样的代码,selenium总是说:当前元素不可点击 但如果我在点击之前添加一些睡眠,它就会起作用。

    public void clickSaveBtn() {
        WebDriverWait waiter = new WebDriverWait(driver, 5, 200);
        waiter.until(ExpectedConditions.presenceOfElementLocated(By.id("save")));
        waiter.until(ExpectedConditions.elementToBeClickable(By.id("save")));
        Thread.sleep(5000);
        saveBtn.click();
    }

为什么呢?方法elementToBeClickable()不可靠吗?

0 个答案:

没有答案