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

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

Introduction

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

Prototype

public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page.

Usage

From source file:io.selendroid.tests.SayHelloWebviewTest.java

License:Apache License

@Test
public void assertThatWebviewSaysHello() throws Exception {
    WebElement button = driver().findElement(By.id("buttonStartWebview"));

    button.click();/*from  w ww.  ja  va  2  s .c om*/
    WebDriverWait wait = new WebDriverWait(driver(), 10);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Go to home screen")));
    driver().switchTo().window("WEBVIEW");

    WebElement inputField = driver().findElement(By.id("name_input"));
    Assert.assertNotNull(inputField);
    inputField.clear();
    inputField.sendKeys("Dominik");

    WebElement car = driver().findElement(By.name("car"));
    Select preferedCar = new Select(car);
    preferedCar.selectByValue("audi");
    inputField.submit();

    WaitingConditions.pageTitleToBe(driver(), "Hello: Dominik");
}

From source file:io.selendroid.tests.UserRegistrationTest.java

License:Apache License

private void verifyUser(UserDO user) throws Exception {
    WebDriverWait wait = new WebDriverWait(driver(), 5);
    WebElement inputUsername = wait/* w  w  w  . j  a  va2 s. c o  m*/
            .until(ExpectedConditions.presenceOfElementLocated(By.id("label_username_data")));

    Assert.assertEquals(inputUsername.getText(), user.getUsername());
    Assert.assertEquals(driver().findElement(By.id("label_email_data")).getText(), user.getEmail());
    Assert.assertEquals(driver().findElement(By.id("label_password_data")).getText(), user.getPassword());
    Assert.assertEquals(driver().findElement(By.id("label_name_data")).getText(), user.getName());
    Assert.assertEquals(driver().findElement(By.id("label_preferedProgrammingLanguage_data")).getText(),
            user.getProgrammingLanguage().getValue());
    Assert.assertEquals(driver().findElement(By.id("label_acceptAdds_data")).getText(), "true");

    driver().findElement(By.id("buttonRegisterUser")).click();
}

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 ww  w  .  j  a va2s  . 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:jscover.server.WebDriverJasmineTestBase.java

License:Open Source License

@Test
public void shouldRunJasmineTestAndStoreResultViaJavaScriptCall() throws Exception {
    File jsonFile = new File(getReportDir() + "/directory/jscoverage.json");
    if (jsonFile.exists())
        jsonFile.delete();/*from   www  .  j  a  va 2  s .  c o m*/

    webClient.get("http://localhost:8081/jscoverage.html");
    webClient.findElement(By.id("location")).clear();
    webClient.findElement(By.id("location")).sendKeys("http://localhost:8081/" + getTestUrl());
    webClient.findElement(By.id("openInWindowButton")).click();

    String handle = webClient.getWindowHandle();
    Set<String> allHandles = webClient.getWindowHandles();
    for (String currentHandle : allHandles) {
        if (!currentHandle.equals(handle)) {
            webClient.switchTo().window(currentHandle);
            break;
        }
    }

    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);

    verifyTotal(webClient, 100, 0, 100);

    webClient.switchTo().window("jscoverage_window");
    ((JavascriptExecutor) webClient).executeScript("jscoverage_report('directory')");

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

From source file:loblaw.provisioning.TicketCreator.java

private void createTicket() {
    try {//  w  w w .j a v  a  2  s  .  c  om

        //   WebElement templateDropdown = (new WebDriverWait(activeBrowser, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"reqTemplateListh\"]/p/span")));
        //  templateDropdown.click();
        //WebElement loblawLine = (new WebDriverWait(activeBrowser, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"reqTemplateList\"]/div/table/tbody/tr/td/ul/li[45]/a")));
        //loblawLine.click();
        Thread.sleep(300);
        WebElement contactName = (new WebDriverWait(activeBrowser, 10)) //added this line
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"reqSearch\"]")));
        contactName.sendKeys("Loblaw");

        WebElement storeNumberArea = (new WebDriverWait(activeBrowser, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"UDF_CHAR2\"]"))));
        storeNumberArea.clear();
        storeNumberArea.sendKeys(storeNumberText);

        WebElement titleArea = (new WebDriverWait(activeBrowser, 10))
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"title\"]")));
        //title format: Loblaw New Site Provisioning - SiteID: [Banner] [Location ID] [Line of Business]
        titleArea.clear();
        titleArea.sendKeys(ticketTitleText);

        WebElement descriptionArea = (new WebDriverWait(activeBrowser, 10)).until(
                ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"zEditor\"]/div/iframe")));
        descriptionArea.sendKeys(Keys.chord(Keys.CONTROL, "a"));
        descriptionArea.sendKeys(ticketDumpText);

        WebElement addRequestButton = (new WebDriverWait(activeBrowser, 10))
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"buttonType\"]")));
        addRequestButton.click();
        Thread.sleep(2000);

    } catch (Exception e) {

        System.out.println("Trying to create ticket, got error:");
        System.out.println(e.getMessage());
    }
}

From source file:main.java.qa.android.util.WaitTool.java

License:Open Source License

/**
  * Wait for the element to be present in the DOM, regardless of being displayed or not.
  * And returns the first WebElement using the given method.
  *//from  www .j av  a  2s . com
  * @param WebDriver   The driver object to be used 
  * @param By   selector to find the element
  * @param int   The time in seconds to wait until returning a failure
  * 
  * @return WebElement   the first WebElement using the given method, or null (if the timeout is reached)
  */
public static WebElement waitForElementPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() 

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        element = wait.until(ExpectedConditions.presenceOfElementLocated(by));

        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return element; //return the element
    } catch (Exception e) {
        Log.info(e.getMessage());
    }
    return null;
}

From source file:modules.sd_uat.pages.EditInformationPage.java

public void handleAddressSuggestion() {
    try {// w w  w  .  j  av  a 2  s  . c o  m
        new WebDriverWait(driver, 20)
                .until(ExpectedConditions.presenceOfElementLocated(By.linkText("force change"))).click();
    } catch (Exception e) {
        System.out.println("Address suggestion was not present");
    }
}

From source file:mooltipass.AutoLoginAft.java

License:Open Source License

/**
 * TODO: check for buttons if links aren't present
 * //from   w  ww .  j av a2s  .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();
}

From source file:net.roddrim.number5.web.selenium.SeleniumWebDriverBot.java

License:Apache License

@Override
public void waitForElementToBePresent() {
    wait.until(ExpectedConditions.presenceOfElementLocated(current));
}

From source file:newMember.newTrial.java

License:Open Source License

public static void main(String[] args) throws IOException {
    //setProperty(a,b): Ensure b is set to path of gecko driver
    //ClassLoader loader = ClassLoader.getSystemClassLoader();
    //URL path = loader.getResource("geckodriver.exe");
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URL url = cl.getResource("geckodriver/geckodriver/geckodriver.exe");
    System.setProperty("webdriver.chrome.driver", url.getPath());

    //System.setProperty("webdriver.gecko.driver", "C:/Users/Sherlock Mind Palace/workspace/TrialRun/geckodriver/geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);

    //Go to testing site
    driver.get("https://apptimize.com");

    //Click on Sign Up button
    driver.findElement(By.xpath("//a[@href='/30-day-trial']")).click();

    //Search for id fname for 10 seconds before giving up
    WebElement fname = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("fname")));
    fname.sendKeys(member.fName);/*from ww w  .ja v a2  s.  c o  m*/

    WebElement lname = driver.findElement(By.id("lname"));
    lname.sendKeys(member.lName);

    //Fill in email field 
    WebElement email = driver.findElement(By.id("email"));
    email.sendKeys(member.eMail);

    //Fill in Company name
    WebElement cname = driver.findElement(By.id("company"));
    cname.sendKeys("Apptimize Candidate");

    //Fill in Phone and Job field
    WebElement phone = driver.findElement(By.id("phone"));
    phone.sendKeys(member.pNumber);

    WebElement jtitle = driver.findElement(By.id("jobtitle"));
    jtitle.sendKeys(member.jTitle);

    //Create password
    WebElement password = driver.findElement(By.id("password"));
    password.sendKeys(member.pWord);

    //Select No to software radio question
    WebElement rNo = driver.findElement(By.xpath("//input[@name='purchased' and @value='No']"));
    rNo.click();

    //Select End User License Agreement Checkbox
    WebElement read = driver.findElement(By.id("eula"));
    read.click();

    //WebElement submit = driver.findElement(By.id("submit"));
    //submit.click();

    System.out.println("You successfully signed up for trial account.");

    driver.quit();

}