I'm trying to click on a button which is visible on a page by using webdriver wait but webdriver is only able to click on the button once I add a
Thread.sleep
to the code.I have also checked the button to see whether its visible (True) before I execute my code and it in turn
returns = true
.
//Button Visiblity check:
List<WebElement> signOutList = driver.findElements(.xpath(".//*[starts-with(@id,'fulfillment-time-type-section-')]/div[2]//button"));
Assert.assertTrue(signOutList.size() > 0);
//The code below Doesn't click on the button
By timeDropdownButton = By.xpath(".//*[starts-with(@id,'fulfillment-time-type-section-')]/div[2]//button");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.elementToBeClickable(timeDropdownButton));
myDynamicElement.click();
//The code below Does click on the button:
Thread.sleep(500);
By timeDropdownButton = By.xpath(".//*[starts-with(@id,'fulfillment-time-type-section-')]/div[2]//button");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.elementToBeClickable(timeDropdownButton));
myDynamicElement.click();
Please note I have also tried to click the button using JS code and WebDriver actions etc
I don't know why 'Wait Clickable' only works when I combine with 'Thread.sleep'?