Example usage for org.openqa.selenium WebElement isDisplayed

List of usage examples for org.openqa.selenium WebElement isDisplayed

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement isDisplayed.

Prototype

boolean isDisplayed();

Source Link

Document

Is this element displayed or not?

Usage

From source file:com.springer.omelet.common.ExpectedConditionExtended.java

License:Apache License

/***
 * Check if all the element in the List are displayed
 * @param elements//from   w  w  w.  ja v a  2 s  . c  o m
 * @return
 */
public static ExpectedCondition<Boolean> elementToBeDisplayed(final List<WebElement> elements) {
    final List<Boolean> statusList = new ArrayList<Boolean>();
    return new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {

            for (WebElement w : elements) {
                try {
                    if (w != null && w.isDisplayed()) {
                        statusList.add(true);
                    } else {
                        return null;
                    }
                } catch (StaleElementReferenceException e) {
                    return null;
                }
            }
            return statusList.size() == elements.size() ? true : false;
        }

        @Override
        public String toString() {
            return "One of the Element is not clickable:";
        }
    };
}

From source file:com.sugarcrm.candybean.examples.mobile.AppiumAndroidTest.java

License:Open Source License

@Test
public void testActive() throws Exception {
    WebElement text = driver.findElement(By.xpath("//textfield[1]"));
    assertTrue(text.isDisplayed());

    WebElement button = driver.findElement(By.xpath("//button[1]"));
    assertTrue(button.isDisplayed());//from  w w w . j a  va2  s.com
}

From source file:com.sugarcrm.candybean.examples.mobile.AppiumIosTest.java

License:Open Source License

@Test
public void testHideKeyboard() throws Exception {
    driver.findElement(By.xpath("//textfield[1]")).sendKeys("12");

    WebElement button = driver.findElement(By.name("Done"));
    assertTrue(button.isDisplayed());

    button.click();//from   ww  w  . j a v a  2  s.c  o  m
}

From source file:com.sugarcrm.candybean.examples.mobile.SugarAndroidTest.java

License:Open Source License

@Test
public void testLogin() throws Exception {
    WebElement username = driver.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/textfield[1]"));
    assertTrue(username.isDisplayed());

    Set<String> handles = driver.getWindowHandles();

    for (String s : handles) {
        System.out.println(s);/* www.  ja  va  2s.  c  o  m*/
    }

    if (!username.getText().equals("")) {
        username.clear();
    }
    username.sendKeys("admin");

    WebElement password = driver.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/secure[1]"));

    assertTrue(password.isDisplayed());

    password.click();

    password.sendKeys("asdf");

    WebElement login = driver.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/link[1]"));

    login.click();

    Thread.sleep(1000000);
}

From source file:com.sugarcrm.candybean.examples.mobile.SugarIosTest.java

License:Open Source License

@Test
public void testLogin() throws CandybeanException {
    WebElement username = iface.wd.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/textfield[1]"));
    assertTrue(username.isDisplayed());
    Set<String> handles = iface.wd.getWindowHandles();
    for (String s : handles) {
        System.out.println(s);/*from ww w. j a  va  2  s .com*/
    }
    if (!username.getText().equals("")) {
        username.clear();
    }
    username.sendKeys("admin");
    WebElement password = iface.wd.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/secure[1]"));
    assertTrue(password.isDisplayed());
    password.click();
    password.sendKeys("asdf");
    WebElement login = iface.wd.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/link[1]"));
    login.click();
    iface.pause(1000000);
}

From source file:com.sugarcrm.candybean.examples.sugar.SugarAndroidTest.java

License:Open Source License

@Test
public void testLogin() throws Exception {
    WebElement username = driver.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/textfield[1]"));
    assertTrue(username.isDisplayed());
    Set<String> handles = driver.getWindowHandles();
    for (String s : handles) {
        System.out.println(s);/*from w  w  w  .  jav  a2  s. com*/
    }
    if (!username.getText().equals("")) {
        username.clear();
    }
    username.sendKeys("admin");
    WebElement password = driver.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/secure[1]"));
    assertTrue(password.isDisplayed());
    password.click();
    password.sendKeys("asdf");
    WebElement login = driver.findElement(By.xpath("//window[1]/scrollview[1]/webview[1]/link[1]"));
    login.click();
    Thread.sleep(1000000);
}

From source file:com.synapticpath.naica.selenium.SeleniumUtils.java

License:Open Source License

/**
 * Call this method to find a WebElement. Several parameters are supported.
 * //  ww w .j a  va 2s. co  m
 * @param elementSelector
 *            Will be used as primary criteria to find an element.
 * @param visible
 *            When not null, will be evaluated for visibility on page. That is, the desired element must
 *            also be visible when true, or invisible when false.
 * @param withText
 *            if specified, the element.getText must match also.
 * @param timeout
 *            positive number of seconds to wait
 * @return the {@link WebElement} when found, null if not found in timeout reached first.
 */
public static WebElement findElementWithTimeout(final SeleniumSelector elementSelector, final Boolean visible,
        final String withText, int timeout) {

    final WebDriver driver = SeleniumTestContext.getInstance().getDriver();

    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(timeout > -1 ? timeout : MAX_WAIT, TimeUnit.SECONDS)
            .pollingEvery(POLL_INTERVAL_MILLIS, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class)
            .ignoring(TimeoutException.class);

    try {
        return wait.until((WebDriver d) -> {
            WebElement e = d.findElement(elementSelector.toBySelector());
            if (e != null && (withText == null || e.getText().contains(withText))
                    && (visible == null || visible && e.isDisplayed() || !visible && !e.isDisplayed())) {
                return e;
            }
            return null;
        });
    } catch (TimeoutException te) {
        logger.severe(format("Element selected by %s, visible:%s, withText:%s was not found in time.",
                elementSelector, visible, withText));
    }

    return null;

}

From source file:com.test.Login_Validation.java

public String Commom_steps(ExtentTest logger, String uname, String pwd) throws Throwable {
    if (!escape) {
        l.gmailLogin(logger);/*from  ww  w  . ja v  a  2s.  c o  m*/
        driver.switchTo().frame(Login.getApp_frame());
        escape = true;
    }
    l.appLogin(uname, pwd, logger);
    String notification = hcl.getNotification(driver);
    System.out.println(notification);
    WebElement username = driver
            .findElement(By.cssSelector("div#cega-body div.nsLoginBox input[ng-model='nsloginctrl.username']"));
    Assert.assertTrue(username.isDisplayed(), "Login page should be displayed");
    logger.log(LogStatus.PASS, "Login page is displayed");
    return notification;
}

From source file:com.test.Login_Validation.java

@Test(priority = 4)
public void sessionOutNotification() throws Throwable {
    logger = Login.report/*from  w w  w .  ja  v a2  s. c  o m*/
            .startTest("Verifying session timeout notification when user is logged out from New tab");
    l.NsLogin(data.getProperty("Emailid"), data.getProperty("pwd"), logger);
    l.gmailLogin(logger);
    Thread.sleep(9000);
    logger.log(LogStatus.INFO, "Opening Ns home page in new tab");
    hcl.openNewTab(driver);
    ArrayList<String> allTabs = new ArrayList<String>(driver.getWindowHandles());
    driver.switchTo().window(allTabs.get(1));
    logger.log(LogStatus.INFO, "Logging out from Netsuite");
    // driver.navigate().to("https://system.na1.netsuite.com/app/center/card.nl?sc=-29&t=dEgUxlGSk&loginSucceeded=T&whence=");
    l.NsLogout();
    hcl.closeCurrentTab_MoveToFirstTab(driver);
    driver.switchTo().window(Login.gmailWindow);
    driver.navigate().to("https://mail.google.com/mail/u/0/#inbox/1554932e0941f621");
    // driver.findElement(By.cssSelector("div[title='Save To NetSuite']")).click();
    String notification = hcl.getNotification(driver);
    System.out.println(notification);

    if (notification.equals("NetSuite session timed out, please login again.")) {
        logger.log(LogStatus.PASS, "[" + notification + "] displayed");
    }
    WebElement username = driver
            .findElement(By.cssSelector("div#cega-body div.nsLoginBox input[ng-model='nsloginctrl.username']"));
    Assert.assertTrue(username.isDisplayed(), "Login page should be displayed");
    logger.log(LogStatus.PASS, "Login page is displayed");

}

From source file:com.testmax.handler.SeleniumBaseHandler.java

License:CDDL license

public boolean isElementDisplayed(By by) {
    if (this.isConditionalElement || isBypassDisplay()) {
        return true;
    } else {//from ww  w .ja  v a2 s  .c  o  m
        try {
            WebElement elm = this.getDriver().findElement(by);

            if (elm != null && elm.isDisplayed()) {
                return true;
            }
        } catch (NoSuchElementException e) {

            this.printMessage("****Element id=" + this.controlIdentifier + " is not Displayed!");
            return false;
        }
    }
    return false;
}