Example usage for org.openqa.selenium.support.ui ExpectedConditions elementToBeClickable

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions elementToBeClickable

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions elementToBeClickable.

Prototype

public static ExpectedCondition<WebElement> elementToBeClickable(final WebElement element) 

Source Link

Document

An expectation for checking an element is visible and enabled such that you can click it.

Usage

From source file:io.github.bonigarcia.wdm.base.BaseBrowserTst.java

License:Open Source License

@Test
public void test() {
    if (validOS) {
        WebDriverWait wait = new WebDriverWait(driver, TIMEOUT);
        driver.get("https://en.wikipedia.org/wiki/Main_Page");

        By searchInput = By.id("searchInput");
        wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
        driver.findElement(searchInput).sendKeys("Software");

        By searchButton = By.id("searchButton");
        wait.until(ExpectedConditions.elementToBeClickable(searchButton));
        driver.findElement(searchButton).click();

        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software"));
    }//from   w  w w. ja  v  a  2 s  .  c o m
}

From source file:io.github.bonigarcia.wdm.test.ChromeTest.java

License:Apache License

@Test
public void test() {
    // Your test code here. For example:
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    By searchInput = By.id("searchInput"); // search for "Software"
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); // assert that the resulting page contains a text
}

From source file:io.github.bonigarcia.wdm.test.ManagerTest.java

License:Open Source License

public void browseWikipedia() {
    WebDriverWait wait = new WebDriverWait(driver, TIMEOUT);
    driver.get("http://en.wikipedia.org/wiki/Main_Page");

    By searchInput = By.id("searchInput");
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");

    By searchButton = By.id("searchButton");
    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"),
            "Computer software or simply software"));
}

From source file:io.github.bonigarcia.wdm.test.PerformanceChromeTest.java

License:Apache License

private void singleTestExcution(WebDriver driver) {
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    By searchInput = By.id("searchInput"); // search for "Software"
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); // assert that the resulting page contains a text
}

From source file:io.github.bonigarcia.wdm.test.PerformancePhantomJsTest.java

License:Apache License

private void singleTestExcution(WebDriver driver) {
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    By searchInput = By.id("searchInput"); // search for "Software"
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");

    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); // assert that the resulting page contains a text
}

From source file:io.github.bonigarcia.wdm.test.RemoteTest.java

License:Apache License

@Test
public void test() {
    WebDriverWait wait = new WebDriverWait(driver, 30);
    driver.get("https://en.wikipedia.org/wiki/Main_Page");
    By searchInput = By.id("searchInput");
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software"));
}

From source file:io.kahu.hawaii.cucumber.glue.html.HtmlSteps.java

License:Apache License

public void acceptCookies() {
    // accept cookies popup
    if (acceptCookies) {
        try {/*from w  w  w  . j  av  a2s  .  com*/
            WebDriverWait wait = new WebDriverWait(webDriver, 2); // wait
            // max 2
            // seconds
            wait.until(ExpectedConditions.elementToBeClickable(By.className("cookie-yes")));
            turnOffImplicitWaits();
            WebElement element = findElement(By.className("cookie-yes"));
            moveTo(element).click().perform();
            Object lock = new Object();
            synchronized (lock) {
                try {
                    lock.wait(1000); // wait 1 second to allow cookie popup
                    // to be closed
                } catch (InterruptedException e) {
                    // ignore
                }
            }

        } catch (NoSuchElementException e) {
            // ignore, cookie popup not displayed
        } catch (TimeoutException e) {
            // ignore, cookie popup not displayed
        }
        turnOnImplicitWaits();
        acceptCookies = false;
    }
}

From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java

License:Apache License

@Test
@DisplayName("Local record")
void localRecordTest() throws Exception {

    setupBrowser("chrome");

    log.info("Local record");

    user.getDriver().findElement(By.id("add-user-btn")).click();
    user.getDriver().findElement(By.className("join-btn")).click();

    user.getEventManager().waitUntilEventReaches("connectionCreated", 1);
    user.getEventManager().waitUntilEventReaches("accessAllowed", 1);
    user.getEventManager().waitUntilEventReaches("streamCreated", 1);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 1);

    int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
    Assert.assertEquals("Expected 1 video but found " + numberOfVideos, 1, numberOfVideos);
    Assert.assertTrue("Video was expected to have audio and video tracks", user.getEventManager()
            .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true));

    WebElement recordBtn = user.getDriver()
            .findElement(By.cssSelector("#openvidu-instance-0 .publisher-rec-btn"));
    recordBtn.click();//from w w  w.j  ava  2 s  . c  o  m

    Thread.sleep(2000);

    WebElement pauseRecordBtn = user.getDriver()
            .findElement(By.cssSelector("#openvidu-instance-0 .publisher-rec-pause-btn"));
    pauseRecordBtn.click();

    Thread.sleep(2000);

    pauseRecordBtn.click();

    Thread.sleep(2000);

    recordBtn.click();

    user.getWaiter().until(ExpectedConditions.elementToBeClickable(By.cssSelector("#recorder-preview video")));

    user.getWaiter().until(
            waitForVideoDuration(user.getDriver().findElement(By.cssSelector("#recorder-preview video")), 4));

    user.getDriver().findElement(By.id("close-record-btn")).click();

    user.getWaiter()
            .until(ExpectedConditions.numberOfElementsToBe(By.cssSelector("#recorder-preview video"), 0));

    gracefullyLeaveParticipants(1);
}

From source file:jscover.server.WebDriverJasmineTestBase.java

License:Open Source License

@Test
public void shouldRunJasmineTestAndStoreResult() throws IOException {
    File jsonFile = new File(getReportDir() + "/jscoverage.json");
    if (jsonFile.exists())
        jsonFile.delete();/*from   w w w . j a v a2  s . co  m*/
    webClient.get("http://localhost:8081/jscoverage.html?" + getTestUrl());

    String handle = webClient.getWindowHandle();
    new WebDriverWait(webClient, 1).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("browserIframe"));
    new WebDriverWait(webClient, 1)
            .until(ExpectedConditions.presenceOfElementLocated(By.className("duration")));
    new WebDriverWait(webClient, 1)
            .until(ExpectedConditions.textToBePresentInElement(By.className("duration"), "finished"));
    verifyJasmineTestsPassed();

    webClient.switchTo().window(handle);

    new WebDriverWait(webClient, 1).until(ExpectedConditions.elementToBeClickable(By.id("storeTab")));
    webClient.findElement(By.id("storeTab")).click();

    new WebDriverWait(webClient, 1).until(ExpectedConditions.elementToBeClickable(By.id("storeButton")));
    webClient.findElement(By.id("storeButton")).click();
    new WebDriverWait(webClient, 2)
            .until(ExpectedConditions.textToBePresentInElement(By.id("storeDiv"), "Coverage data stored at"));

    webClient.get(format("http://localhost:8081/%s/jscoverage.html", getReportDir()));
    verifyTotal(webClient, 100, 0, 100);
}

From source file:mooltipass.AutoLoginAft.java

License:Open Source License

/**
 * TODO: check for buttons if links aren't present
 * /*from w w w .j  a  v a 2  s  .  c o  m*/
 * @param loginUrl
 * @param loginLoadedLinkText - link text used to determine when page has loaded
 * @param logoutLinkText - link text to click to log out at end of test
 * @throws Exception
 */
void testAutoLogin(String loginUrl, String loginLoadedLinkText, String logoutLinkText) throws Exception {
    driver.get(loginUrl);
    WebDriverWait wait = new WebDriverWait(driver, getTimeout());
    // wait for Login, but we are not gonna click it testing AUTOACCEPT works.
    // TODO fix assumption that all sites have a direct Login page, but not all do.  
    if (loginLoadedLinkText != null && !loginLoadedLinkText.equals("")) {
        wait.until(ExpectedConditions.elementToBeClickable(By.linkText(loginLoadedLinkText)));
    } else {
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html")));
    }

    screenshot(); // of given loginUrl

    // various in page login pop-ups are detected by MP and can be submitted without clicking the link
    // that makes them visible.
    // TODO handle the other cases
    if (loginLoadedLinkText != null && !loginLoadedLinkText.equals("")) {
        wait.until(ExpectedConditions.elementToBeClickable(By.linkText(loginLoadedLinkText)));
    }

    Thread.sleep(1000);

    if (logoutLinkText != null && !logoutLinkText.equals("")) {
        WebElement logout = wait.until(ExpectedConditions.elementToBeClickable(By.linkText(logoutLinkText)));
        //         logout.click(); // clicking log out is nearly useless, MP will log back in immediately with AUTOACCEPT
    } else {
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html")));
    }
    screenshot();
}