I have a custom wait method defined as:
public IWebElement WaitForElementClickable(IWebDriver _driver, By elementName)
{
var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(20));
return wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(elementName))
}
I have one place where I click on a button and a new page loads, it sticks on "loading" for a few seconds (2-3 secs) and then I want to click on something else once it loads....
public void enterSearchInfo()
{
//Thread.Sleep(2000);
IWebElement selectElement = utility.WaitForElementClickable(_driver, element);
selectElement.Click();
}
Even though I have the wait method set to 20 secs this only works 5 times out of 10, the other 5 times I get the following error...
OpenQA.Selenium.ElementClickInterceptedException: element click intercepted:
When I uncomment Thread.Sleep(2000)
it works 10 out of 10 times
Is there a better way to handle this than the wait for element clickable
method? I'd rather not be hardcoding sleep waits in my code.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…