Using WebDrivers Action Builders

WebDriver’s Action class allows the user to perform a sequence of actions inside of one method. The example below checks the Air, Monitoring, Water, Pollution Prevention and All checkboxes and then clicks the Submit Order button and finishes by dismissing the modal dialog.


NOTE: The test execution has been slowed down for demo purposes

Example Code:

package com.demo.test;
 
public class ActionBuilderExampleTest extends BaseTest {
...
    @Test
    public void Move() {
        getWebDriver().get(getTestBaseUrl());

        WebElement button = getWebDriver().findElement(By.xpath("//tbody/tr[3]/td/form/input[3]"));
        List listItems = getWebDriver().findElements(By.name("list"));

        Actions builder = new Actions(getWebDriver());
        Sleeper.sleepTight(CosConstant.LARGE_DELAY);
        builder.click(listItems.get(1)).click(listItems.get(2)).click(listItems.get(3)).click(listItems.get(4)).click(listItems.get(0)).click(button);
        Action selectMultiple = builder.build();
        Sleeper.sleepTight(CosConstant.LARGE_DELAY);

        selectMultiple.perform();

        Sleeper.sleepTight(CosConstant.LARGE_DELAY);
        getWebDriver().switchTo().alert().dismiss();
        Sleeper.sleepTight(CosConstant.LARGE_DELAY);
    }

}

Leave a Reply

Download and extend ATF...

ATF Is Now Open Source

Join this 10 week program anytime...

DevOps Mastery Program

Get your DevOps health check now...

Free DevOps Assessment

X