[英]How to wait page to load selenium java
I'm trying to find a way to make page to wait until all the elements in the page are fully updated.我试图找到一种方法让页面等到页面中的所有元素都完全更新。 For example if I need to do a click which changes some value on my screen, and I want to wait until the value has been updated.
例如,如果我需要单击更改屏幕上的某些值,并且我想等到值更新。
I'm searching for some generic action which I can use in many places in my program.我正在寻找一些可以在我的程序的许多地方使用的通用操作。 The system is written with react, may I have any way to get to the reactjs components through java selenium?
系统是用react写的,请问有什么办法可以通过java selenium来获取reactjs组件吗? Or some other good way to make this wait happen?
或者其他一些让这种等待发生的好方法?
you can use javascript executor to check entire web page has loaded.您可以使用 javascript 执行程序来检查整个 web 页面是否已加载。 You need to add wait for 'document.readyState' to be equal to 'complete'.
您需要添加等待“document.readyState”等于“完成”。
This is a generic solution,for some of the elements you may need to add wait explicit wait.这是一个通用的解决方案,对于某些您可能需要添加等待显式等待的元素。 It depends on web application under test
它取决于被测的 web 应用程序
To check if page has loaded, use code below要检查页面是否已加载,请使用以下代码
WebDriverWait wait = new WebDriverWait(driver,timeOutInSeconds);
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
@NullableDecl
@Override
public Boolean apply(@NullableDecl WebDriver input) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
wait.until(pageLoadCondition);
There is no silver bullet for waiting until the whole page has loaded with javascript frameworks like jQuery, react, AngularJS etc.等待整个页面加载 javascript 框架,如 jQuery、react、AngularJS 等,没有什么灵丹妙药。
You will either have to wait until the last change in the page DOM has completed or the more proper way of waiting until the element you want to use is ready for consumption.您要么必须等到页面 DOM 中的最后一次更改完成,要么更合适的方法是等到您要使用的元素准备好使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.