[Selenium] Common functions Comparison

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.