Show wait can be a custom wait condition when you perform the next operation
The wait for the display needs to be done somewhere else where synchronization is needed without affecting the script.
Selenium Webdriver provides webdriverwait and Expectedcondition classes to perform display waits
The Expectedcondition class provides a series of predefined conditions to wait for. Here are some common conditions
Pre-defined conditions |
Method name |
Element visible clickable |
Elementtobeclickable (by Locator) |
Element can be selected |
Elementtobeselected (webelement Element) |
There is an element |
Presenceofelementlocated (by Locator) |
The specified text appears in the element |
Texttobepresentinelement (by Locator) |
The value of the element |
Texttobepresentinelementvalue (by locator, String text) |
Title |
Titlecontains (String title) |
Webdriverwait calls Expectedcondition every 500 milliseconds until the correct return value is obtained. The advantage is to keep control of what is needed and where to wait, to control the waiting conditions more precisely.
1 Public voidtestwithimplicitwait () {2System.setproperty ("Webdriver.chrome.driver", "Chromedriver.exe");3Webdriver Driver =Newchromedriver ();4Driver.get ("http://map.baidu.com");5 6Webelement curcity = driver.findelement (By.id ("Curcity"));7 Curcity.click ();8 9 //set wait time 10 secondsTenwebdriverwait wait =NewWebdriverwait (driver,10); One //wait until match element text content appears AWait.until (Expectedconditions.texttobepresentinelement (By.id ("Selcityhotcityid"), "national")); - - driver.quit (); the}
Sample Code
[Selenium Webdriver Java] display of wait synchronization