1. Using Thread.Sleep (), this is the most stupid method, but sometimes it can be used and very useful.
2. Implicit wait, implicit wait is when you want to find the element, and this element does not appear immediately, tell Webdriver to query the DOM for a certain time. The default value is 0, but after the setting, the time will work for the entire life cycle of the Webdriver object instance. Webdriver dr = new Firefoxdriver (); dr.manage (). Timeouts (). implicitlywait (timeunit.seconds);3. Using JavaScriptwebelement element = driver.findelement (By.xpath (test));( (Javascriptexecutor) driver). Executescript ("arguments[0].style.border=" 5px Solid Yellow "", Element);
4. Display wait, recommended use display wait
webdriverwait wait = new Webdriverwait (DR, 10);
Wait.until (expectedconditions.visibilityofelementlocated (by.id ("kw"));
Explicitly 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
(1) Whether the page element is available on the page and can be clicked: Elementtobeclickable (by locator)
(2) the page element is selected: elementtobeselected (webelement Element)
(3) page elements exist in the page: presenceofelementlocated (by locator)
(4) Whether a specific text is included in the page element: Texttobepresentinelement (by locator)
(5) page element value: Texttobepresentinelementvalue (by locator, java.lang.String text)
(6) 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.
webdriverwait wait = new webdriverwait (driver,5);
Wait.until (expectedconditions.presenceofelementlocated (By.cssselector (")));
Selenium: 4 ways the element waits