问题
Website is taking time to load when requesting a data from it.
If website loads within 60 seconds, then everything is ok. Beyond that time, it throws me to error section.
Actually, this code is executing for 60 sections only.
this.driver.FindElement(By.CssSelector("#btnLogin")).Click();
How to set the driver to wait for this code to be executed completely?
Thank you
回答1:
You can increase page load wait time beyond the 60 seconds(default), say example 70 seconds as given below.
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(70);
回答2:
There is many option to set page load time out.
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(90);
OR
driver.Manage().Timeouts().ImplicitWait.Add(System.TimeSpan.FromSeconds(90));
OR
driver.Manage().Timeouts().PageLoad.Add(System.TimeSpan.FromSeconds(90));
OR
driver.Manage().Timeouts().AsynchronousJavaScript.Add(90));
Updated-1
You can try to wait an element’s presence on new page (page appears after page load). Write a custom method to find element with timeout like below
public static class WebDriverExtensions
{
public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(driver => driver.FindElement(by));
}
return driver.FindElement(by);
}
}
Usage of above method:
driver.FindElement(By.CssSelector("#btnLogin"), 90);
来源:https://stackoverflow.com/questions/60386916/how-to-increase-code-execution-time-limit-in-selenium-webdriver-using-c-sharp