Sample code of Java selenium intelligent waiting for page loading to complete

Java selenium intelligently waits for the page to load

We often encounter when using selenium to operate an element on a page. We need to wait for the page to load before we can operate. Otherwise, an exception will be thrown if the element on the page does not exist.

Or when we encounter Ajax asynchronous loading, we need to wait for the element loading to complete before we can operate

Selenium provides a very simple and intelligent method to judge whether an element exists

Reading catalog

Example requirements

Instance: Set_ timeout. For the HTML code under HTML, click the click button for 5 seconds, and a red div will appear on the page. We need to write an automatic script to intelligently judge whether the div exists, and then highlight the Div.

Implicit waiting

among

driver. manage(). timeouts(). implicitlyWait(10,TimeUnit.SECONDS);

This means that wait for 10 seconds in total. If the element does not exist after 10 seconds, an exception org. Org will be thrown openqa. selenium. NoSuchElementException

Explicit wait

Explicit wait uses the built-in method in the expectedconditions class to judge the explicit wait.

Explicit waiting can customize the waiting conditions for more complex page waiting conditions

Only when the explicit wait condition is met, the test code will continue to execute the subsequent test logic backward

If the set maximum explicit wait time threshold is exceeded, the test program will throw an exception.

The above is to sort out the data waiting for the page loading of Java selenium. We will continue to supplement relevant data in the future. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>