为什么我的等待方法没有点击预定的按钮?
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);
}
定位器:
public @FindBy(xpath=".//*[@id='prd_listing']/div/li[1]/a") WebElement link_FirstSupercarOption;