Why doesn't my wait method click on the intended button?
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);
}
}
If I use Thread.sleep infront of the method it seems to click on the button:
@Test(priority=4)
public void clickOnFirstSuperCarOption() throws Exception
{
Thread.sleep(2000);
basePage.waitAndClickElement(supercarsPage.link_FirstSupercarOption);
}
Locator:
public @FindBy(xpath=".//*[@id='prd_listing']/div/li[1]/a") WebElement link_FirstSupercarOption;