简体   繁体   English

如何等待页面加载 selenium java

[英]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.

相关问题 等待 Selenium 中的页面加载 - Wait for page load in Selenium Selenium-Java等待页面加载在测试脚本中失败 - Selenium - Java Wait for page to load fails in test scripts 等待页面在 Selenium 中完全加载 - Wait for a page to fully load in Selenium 如何在 Selenium 中使用 JavaScript 等待页面完全加载 - How to wait for page to load completely using JavaScript in Selenium 如何让Selenium WebDriver不要等待页面的完全加载 - How to make Selenium WebDriver not to wait for complete load of the page Selenium SafariDriver不等待页面加载吗? - Selenium SafariDriver doesn't wait for page to load? Selenium WebDriver:等待带有 JavaScript 的复杂页面加载 - Selenium WebDriver: Wait for complex page with JavaScript to load 我想要一个方法,它可以等待页面中的所有webelements加载到java(Selenium webdiver) - i want a method which can will wait for all the webelements in a page to load in java(Selenium webdiver) Selenium Webdriver - 等待页面完全加载Java和JavaScript(ajax / jquery / animation等) - Selenium Webdriver - wait for page to completely load in Java&JavaScript(ajax/jquery/animation etc.) 多个测试用例执行:我想在Java中等待硒中的整个页面加载 - Multiple test case execution: I want to wait for entire page load in selenium in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM