我的代码中有各种方法,我需要使用WebDriverWait。通常我们在main方法中声明它:WebDriverWait mywait = new WebDriverWait(driver,25)。 虽然在selenium中使用junit没有主要的方法,但是如何在我的代码中以各种方法使用WebDriverWait for the mebelements ???
答案 0 :(得分:0)
这里有一些帮助:How do I run JUnit tests from inside my java application?
或者您只需添加Thread.sleep(millisecodns)
即可尝试{ 了Thread.sleep(100); } catch(InterruptedException e){ // TODO自动生成的catch块 e.printStackTrace(); }
它必须在JAVA(Eclipse)中运行 但你也可以使用(我认为更适合测试:):
FluentWait fluentWait = new FluentWait<>(webDriver) {
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(200, TimeUnit.MILLISECONDS);
.ignoring(NoSuchElementException.class);
}
WebElement element = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.elementToBeClickable(By.id("someid")));