有什么办法可以避免使用driver.wait or driver.sleep
命令?有没有办法避免在硒中使用等待和睡眠?
像driver.manage().timeouts().implicitlyWait(3000)
之类的东西被用作一般超时,直到元素位于?
我在自动测试新的编码硒:)
有什么办法可以避免使用driver.wait or driver.sleep
命令?有没有办法避免在硒中使用等待和睡眠?
像driver.manage().timeouts().implicitlyWait(3000)
之类的东西被用作一般超时,直到元素位于?
我在自动测试新的编码硒:)
可以建立显性和隐性的等待。
显式的一个例子等待即等待明确地特定元素出现:
IWebDriver driver = new FirefoxDriver();
driver.Url = "http://somedomain/url_that_delays_loading";
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Id("someDynamicElement"));
});
一个隐式的等待的一个例子(即,等待的时间的任意的量)是:
WebDriver driver = new FirefoxDriver();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver.Url = "http://somedomain/url_that_delays_loading";
IWebElement myDynamicElement = driver.FindElement(By.Id("someDynamicElement"));
有关更多信息,请参阅here。
您可以使用显式的等待
new WebDriverWait(driver, new TimeSpan(0, 1, 0)).Until(ExpectedConditions.ElementIsVisible(By locator));
等待的元素一分钟。
非常感谢您的回答。我设法让一个“弯路”有以下几点:
function findClickElem(locator, path, timeout) {
driver.wait(generalspecs.getSpecs().until.elementLocated(generalspecs.getSpecs().By[locator](path)), timeout).then(function(elem){
if(elem){
elem.click();
}else{
console.log('no element!');
}
});
}
刚刚添加到generalspecs,每次我用等待和点击元素时被调用。
findClickElem("xpath" ,"//li[contains(@class, 'classCustom1')]", 15000);
我的回答有帮助吗? –
我设法使用一般规格中使用的波纹管方法“绕道”,但您的答案肯定有帮助,谢谢。 – MirceaM