1
我想在硒中执行一个操作,它将等待状态更改为某个“完成”状态。硒有条件的等待与中间行为
从概念上讲,它可以在伪代码中排列为这样:
public boolean waitForActionToComplete(long maxTimeoutInSeconds, int repeatTimeInSeconds, Callable<T> action, Callable<T> condition) {
long startTime = 0;
while (startTime < maxTimeoutInSeconds)
perform <action>; // e.g., click on a "Refresh" button to refresh the results
boolean done = verify <condition>; // e.g., check whether the job status is "Done"
if (done)
return true; // if done, then exit with TRUE
else
Thread.sleep(repeatTimeInSeconds);
end while;
return false; // status still not complete, timeout gracefully
}
这种方法可以容易与ExpectedCondition和WebdriverWait/FluentWait稍微简单的方法来实现。但是,由于框架中的某些约束,我无法精确地实现和使用像这样的方法。以上方法都必须执行,因为这(在框架具有这种方法签名实现一个接口):
public void execute(final WebDriver webDriver, String... parameters) {
// implementation here
}
谁能告诉我如何改造方法在上述规定的形式?
您应该调查[WebDriverWait](HTTPS ://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/WebDriverWait.html)和[FluentWait](https://seleniumhq.github.io/selenium/docs/ API/JAVA /组织/ openqa /硒/支撑/ UI/FluentWait.html)。 – JeffC
谢谢JeffC。我很感激。这说得通。我想我没有完成上面的问题陈述。我现在已经完成了。 – naspras
您仍可以使用FluentWait进行描述。你只需要自己实现它就可以使用任何'verify'。 –
JeffC