为什么我的'等待方法'没有点击预定的按钮?

时间:2017-01-17 12:54:40

标签: java selenium selenium-webdriver webdriver

为什么我的等待方法没有点击预定的按钮?

    public void waitAndClickElement(WebElement element) throws InterruptedException {
    this.wait = new WebDriverWait(driver, 30);
    Boolean elementPresent = wait.until(ExpectedConditions.elementToBeClickable(element)).isEnabled();
    try {
        if(elementPresent==true){
            wait.until(ExpectedConditions.visibilityOf(element)).click();
            //clickElementUsingJS(element);
        }else {
            System.out.println("The specified element cannot be found: " + element);
        }
    } catch(Exception e) {
        throw(e);
    }
}

如果我使用方法的前面的Thread.sleep,它似乎点击按钮:

    @Test(priority=4) 
public void clickOnFirstSuperCarOption() throws Exception 
{
    Thread.sleep(2000);
    basePage.waitAndClickElement(supercarsPage.link_FirstSupercarOption);
}

enter image description here

定位器:

public @FindBy(xpath=".//*[@id='prd_listing']/div/li[1]/a") WebElement link_FirstSupercarOption;

0 个答案:

没有答案