你如何使Selenium 2.0等待页面加载?
当尝试使用ExpectedConditions显式等待元素变得可见时,Visual Studio警告我它现在已经过时,很快就会从Selenium中删除.
实现相同结果的当前/新方法是什么?
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
var element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("content-section")));
Run Code Online (Sandbox Code Playgroud) 我正在使用Selenium 2.20 WebDriver使用C#创建和管理firefox浏览器.要访问页面,我使用以下代码,在访问URL之前设置驱动程序超时:
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)); // Set implicit wait timeouts to 5 secs
driver.Manage().Timeouts().SetScriptTimeout(new TimeSpan(0, 0, 0, 5)); // Set script timeouts to 5 secs
driver.Navigate().GoToUrl(myUrl); // Goto page url
Run Code Online (Sandbox Code Playgroud)
问题是有时页面需要永远加载,并且看起来使用selenium WebDriver加载页面的默认超时是30秒,这太长了.我不相信我设置的超时适用于使用GoToUrl()方法加载页面.
所以我试图弄清楚如何设置页面加载的超时,但是,我找不到任何实际工作的属性或方法.当我单击一个元素时,默认的30秒超时似乎也适用.
有没有办法将页面加载超时设置为特定值,以便当我调用GoToUrl()方法时,它只会等待我指定的时间才能继续?