Instance requirements
Example: set_timeout.html The following HTML code, after clicking the click button for 5 seconds, a red div will appear on the page quickly, we need to write an automated script to determine whether the div exists, and then highlight the Div.
Implicit wait Webdriver Driver = new Firefoxdriver (); Driver.get ("file:///C:/Users/Tank/Desktop/set_timeout.html"); Driver.manage (). Timeouts (). implicitlywait (timeunit.seconds); webelement element = Driver.findelement (By.cssselector (". Red_box")); ((Javascriptexecutor) driver). Executescript ("Arguments[0].style.border = \" 5px solid yellow\ "", Element);
which
Driver.manage (). Timeouts (). implicitlywait (Timeunit.seconds);
This means that for a total of 10 seconds, if the element does not exist after 10 seconds, an exception will be thrown org.openqa.selenium.NoSuchElementException
Explicit waitExplicitly waiting to use the Expectedconditions class in the self-contained method, you can make a trial wait for the judgment.
Explicitly waiting for a condition that can be customized for more complex page-waiting conditions
Condition of waiting |
Webdriver method |
Whether page elements are available on the page and can be clicked |
Elementtobeclickable (by Locator) |
The page element is in the selected state |
Elementtobeselected (webelement Element) |
Page elements exist in the page |
Presenceofelementlocated (by Locator) |
Whether to include specific text in the page element |
Texttobepresentinelement (by Locator) |
Page element values |
Texttobepresentinelementvalue (by locator, java.lang.String text) |
Caption (title) |
Titlecontains (java.lang.String title) |
The test code will continue to execute the subsequent test logic backwards only if the condition satisfies the explicit wait
If the maximum explicit wait time threshold is exceeded, the test program throws an exception.
public static void TestWait2 (Webdriver driver) { driver.get ("E:\\stashfolder\\[email protected]\\stash\\ tank-moneyproject\\ Pudong Software Park Training center \ \ My textbook \\Selenium webdriver\\set_timeout.html "); webdriverwait wait = new webdriverwait (driver, a); Wait.until (expectedconditions.presenceofelementlocated (By.cssselector (". Red_box")); webelement element = Driver.findelement (By.cssselector (". Red_box")); ((Javascriptexecutor) driver). Executescript ("Arguments[0].style.border = \" 5px solid yellow\ "", Element); }
Java Selenium (13) Smart Wait page loading complete