1.Wait for element in default time or self defined time
When the element is need some time to be present, is visible, be is not present or is not visible, for example:loading icon, Waiting time is very import to get the element.
**seleniumutil.waitforelementnotvisible (Driver, By.cssselector ("Div#window-waiting-box"), "waiting box should Disppear in default time which was configured as Timeoutinseconds in Environment.xml ");
*seleniumutil.waitforelementnotvisible (Driver, By.cssselector ("Div#window-waiting-box"), "waiting box should Disappear in 120s ");
2.Explicit wait
(1) New webdriverwait (Driver, 10). Until (expectedconditions.elementtobeclickable (locator));
(2) New webdriverwait (Driver, 10). Until (expectedconditions.visibilityof (locator));
(3) New webdriverwait (Driver, 10). Until (expectedconditions.presenceofelementlocated (locator);
(4)
Function<webdriver, webelement> waitfn = new Function<webdriver, webelement> () {
@Override
Public webelement apply (Webdriver driver) {
Return El.findelement (By.cssselector ("Div.rptstatus.rptcomplete"));
}
};
Detect every 2 seconds, the maximum time is seconds
webdriverwait wait = new webdriverwait (Driver, 120, 2);
Wait.withmessage ("A processing icon should display in the Status column ' in the row.")
Wait.until (WAITFN);
3.waitForElementVisible VS waitforelementpresent
*seleniumutil.waitforelementvisible (Driver, By.cssselector ("Input#btnclose"), "Close button exists but not visible") * *seleniumutil.waitforelementpresent (Driver, By.cssselector ("Input#btnclose"), "Close button doesn ' t exist")
4.waitforelementpresent VS waitforallelementspresent *webelement element = seleniumutil.waitforelementpresent (Driver, By.cssselector ("input[value=" "+buttonname+" '] ")," Cannot get button named: "+buttonname);**list<webelement> elementlist =Seleniumutil.waitforallelementspresent(Driver, By.cssselector("DIV.RTQ-grid-row[rowID] ")," Cannot get Folders list ");
5.Some element might is present/visible, it also might not. But both conditions is correct.
For Example:alert Dialog
In this condition, we need to use try{...} catch ()
6.Find element under another element
Permissionel.findelement (By.cssselector ("input[value= ' true ')")
Seleniumutil.waitforelementvisible (Driver, By.cssselector (". Top-bottom-split"), Workspaceel);
public void Catchifpopupdialogandclickclose () {
try{
Seleniumutil.waitforelementvisible (Driver, By.cssselector ("Input#btnclose"). Click ();
Logger.info ("Dialog pops up");
}
catch (Exception e)
{
Logger.info ("No dialog pops up");
}
}
[Selenium] Common functions Comparison