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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.playphone.alex.ListViewXpathDemo.java

License:Apache License

public void runDemo() throws MalformedURLException {
    setupAppium();/* ww  w  . j av  a 2s .c om*/
    WebDriverWait localWait = new WebDriverWait(driver, 5);
    AndroidElement myListView = (AndroidElement) localWait
            .until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId("list view")));

    List<MobileElement> listChildren = myListView.findElementsByClassName("android.widget.TextView");
    AndroidElement firstChild = (AndroidElement) listChildren.get(0);
    System.out.println("Scrolling first element off screen");
    Point upperLeft = firstChild.getLocation();
    Dimension childSize = firstChild.getSize();
    System.out.println(
            "First child dimensions: Point(" + upperLeft.toString() + "), Dim(" + childSize.toString() + ")");
    System.out.println("First child text: " + firstChild.getText());
    int x = childSize.getWidth() / 2;

    Dimension screenSize = driver.manage().window().getSize();

    driver.swipe(x, screenSize.getHeight() - 1, x, upperLeft.getY(), 3000);

    System.out.println("Now printing the values of the first child again to see what the values are:");
    upperLeft = firstChild.getLocation();
    childSize = firstChild.getSize();
    System.out.println(
            "First child dimensions: Point(" + upperLeft.toString() + "), Dim(" + childSize.toString() + ")");
    System.out.println("First child text: " + firstChild.getText());

    cleanupAppium();
}

From source file:com.qkn.automation.pages.LoginPage.java

public void loginWithValidCredentialsForIos(String email, String password) throws Exception {
    try {//from  w  w  w  .  j  a  v a 2s  . c  o  m
        Thread.sleep(5000);

        WebDriverWait wait = new WebDriverWait(pageDriver, 120);

        /*if (pageDriver.getPageSource().contains("Ignore")){
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(pageprops.getProperty("APP_UPGRADE_POPUP"))));
        pageDriver.findElement(By.xpath(pageprops.getProperty("APP_UPGRADE_POPUP"))).click();}*/

        wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(pageprops.getProperty("SIGNIN_BTN"))));
        pageDriver.findElement(By.name(pageprops.getProperty("SIGNIN_BTN"))).click();
        Thread.sleep(15000);
        wait.until(ExpectedConditions
                .visibilityOfElementLocated(By.name(pageprops.getProperty("LOGIN_USERNAME"))));
        findElementByNameclear("UIATextField", "label", "User ID or email");
        findElementByNameAndSendKeys("UIATextField", "label", "User ID or email", email);
        System.out.println("Before sendkeys for password");
        findElementByNameAndSendKeys("UIASecureTextField", "label", "password", password);
        Thread.sleep(10000);
        JavascriptExecutor jse = (JavascriptExecutor) pageDriver;
        jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Go'].tap();");
        Thread.sleep(20000);
        /*   wait.until(ExpectedConditions.visibilityOfElementLocated(By
              .name(pageprops
             .getProperty("OK_BTN"))));*/

        if (pageDriver.getPageSource().contains("OK")) {
            pageDriver.findElement(By.name("OK")).click();
        }

        else {
            Thread.sleep(3000);
        }

        Thread.sleep(10000);

    } catch (Exception e) {
        MintLogger.log(Level.INFO, "Unable to login");
        e.printStackTrace();
    }
}

From source file:com.qkn.automation.pages.LoginPage.java

public void loginIosApplitools(String email, String password) throws Exception {
    try {/*from w  w  w  .  j av  a  2  s . c  o m*/

        WebDriverWait wait = new WebDriverWait(pageDriver, 30);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(pageprops.getProperty("SIGNIN_BTN"))));
        eyes.checkWindow("IOS Welcome page");
        pageDriver.findElement(By.name(pageprops.getProperty("SIGNIN_BTN"))).click();
        Thread.sleep(20000);
        //applitools to test sign in page 
        eyes.checkWindow("IOS Sign in page");
        wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.name(pageprops.getProperty("LOGIN_USERID"))));

        System.out.println("Before send keys for username");
        findElementByNameAndSendKeys("UIATextField", "label", "User ID or email", email);

        System.out.println("Before sendkeys for password");
        findElementByNameAndSendKeys("UIASecureTextField", "label", "password", password);
        Thread.sleep(10000);
        //   wait.until(ExpectedConditions.elementToBeClickable(By.name(pageprops.getProperty("LOGIN_BTN"))));   
        //   pageDriver.findElement(By.xpath(pageprops.getProperty("LOGIN_BTN"))).click();
        //  pageDriver.findElement(By.className("UIAImage")).click();

        JavascriptExecutor jse = (JavascriptExecutor) pageDriver;
        jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Go'].tap();");
        //Thread.sleep(30000);

        wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(pageprops.getProperty("OK_BTN"))));
        eyes.checkWindow("IOS Notification Popup");
        Thread.sleep(5000);
        if (pageDriver.getPageSource().contains("OK")) {
            pageDriver.findElement(By.name("OK")).click();
        }

        Thread.sleep(23000);

    } catch (Exception e) {
        MintLogger.log(Level.INFO, "Unable to login");
        e.printStackTrace();
    }
}

From source file:com.qkn.automation.pages.LoginPage.java

public void loginViaGetStartedIos(String email, String password) throws Exception {
    try {/*from   ww  w  . j a va2s.  c om*/
        WebDriverWait wait = new WebDriverWait(pageDriver, 120);
        pageDriver.findElement(By.name(pageprops.getProperty("GET_STARTED_BTN"))).click();
        Thread.sleep(10000);
        Thread.sleep(10000);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(pageprops.getProperty("SIGNIN_BTN"))));
        pageDriver.findElement(By.name(pageprops.getProperty("SIGNIN_BTN"))).click();
        Thread.sleep(20000);
        wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.name(pageprops.getProperty("LOGIN_USERID"))));
        System.out.println("Before send keys for username");
        findElementByNameAndSendKeys("UIATextField", "label", "User ID or email", email);
        System.out.println("Before sendkeys for password");
        findElementByNameAndSendKeys("UIASecureTextField", "label", "password", password);
        Thread.sleep(10000);
        //   wait.until(ExpectedConditions.elementToBeClickable(By.name(pageprops.getProperty("LOGIN_BTN"))));   
        //   pageDriver.findElement(By.xpath(pageprops.getProperty("LOGIN_BTN"))).click();
        //  pageDriver.findElement(By.className("UIAImage")).click();

        JavascriptExecutor jse = (JavascriptExecutor) pageDriver;
        jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Go'].tap();");
        Thread.sleep(20000);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(pageprops.getProperty("OK_BTN"))));
        if (pageDriver.getPageSource().contains("OK")) {
            pageDriver.findElement(By.name("OK")).click();
        }
        Thread.sleep(13000);

    } catch (Exception e) {
        MintLogger.log(Level.INFO, "Unable to login via Get Started");
        e.printStackTrace();
    }
}

From source file:com.qkn.automation.pages.LoginPage.java

public void loginWithValidCredentialsForAndroidQKN(String email, String password) throws Exception {
    try {//ww  w  . ja  v  a 2s. co  m
        WebDriverWait wait = new WebDriverWait(pageDriver, 30);
        //         pageDriver.findElement(By.name(pageprops.getProperty("SINGUP_BUTTON_LOGINPAGE")))
        //         .click();
        findElementByXpathAndClick(pageDriver, pageprops.getProperty("SINGUP_BUTTON_LOGINPAGE"));
        //         pageDriver.findElement(By.xpath(pageprops.getProperty("SINGUP_BUTTON_LOGINPAGE"))).click();

        //         Thread.sleep(TestConstants.MINSLEEPTIME);
        //applitools to test sign in page 
        //   eyes.checkWindow("Sign in page");   
        //
        wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.id(pageprops.getProperty("LOGIN_USERNAME"))));
        pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(Keys.CONTROL + "a");
        pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(Keys.DELETE);
        System.out.println("Before send keys for username");
        pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(email);
        pageDriver.findElement(By.xpath(pageprops.getProperty("LOGIN_PWD2"))).sendKeys(Keys.CONTROL + "a");
        pageDriver.findElement(By.xpath(pageprops.getProperty("LOGIN_PWD2"))).sendKeys(Keys.DELETE);
        //   Thread.sleep(3000);
        System.out.println("Before sendkeys for password");
        pageDriver.findElement(By.xpath(pageprops.getProperty("LOGIN_PWD2"))).sendKeys(password);
        //         Thread.sleep(5000);

        //Require this to run on local to hide the keyboard not required on sauce labs .
        //         pageDriver.navigate().back();

        /*JavascriptExecutor js = (JavascriptExecutor) pageDriver;
        HashMap flickObject = new HashMap();
        flickObject.put("endX", 0);
        flickObject.put("endY", 0);
        flickObject.put("touchCount", 1);
        js.executeScript("mobile: swipe", flickObject);*/

        // Added by ashwini
        //  eyes.checkWindow("Sign in Page");   
        findElementByXpathAndClick(pageDriver, pageprops.getProperty("SIGNIN_BTN"));
        //         pageDriver.findElement(By.xpath(pageprops.getProperty("SIGNIN_BTN"))).click();
        /*JavascriptExecutor jse = (JavascriptExecutor) pageDriver;
        jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Go'].tap();");      */
        //   Thread.sleep(20000);

        //         Thread.sleep(15000);
        /*wait.until(ExpectedConditions.visibilityOfElementLocated(By
              .name(pageprops
             .getProperty("OK_BTN"))));*/
        //            if(pageDriver.findElements(By.xpath("//android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.Button[1]")).size()!=0)
        //            {
        //               MintLogger.log(Level.INFO,"Welcome to quicken screen displayed So click on OK button");
        //               
        //            }
        wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.xpath(pageprops.getProperty("SIGNINOK_BTN"))));
        findElementByXpathAndClick(pageDriver, pageprops.getProperty("SIGNINOK_BTN"));
        QuickenLogger.log(Level.INFO,
                "Login successfull with " + email + " as username and " + password + " as password");

        //         if (pageDriver.getPageSource().contains("OK")) {
        ////            pageDriver.findElement(By.name("OK")).click();
        //            pageDriver.findElement(By.xpath("//android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.Button[1]")).click();
        //            System.out.println("Login successfull with "+email+" as username and "+password+" as password");
        //         }

        Thread.sleep(TestConstants.MINSLEEPTIME);
        /*
        if (tabname.equalsIgnoreCase("OVERVIEW")){
        pageDriver.findElement(By.name(pageprops.getProperty("OVERVIEW_TAB")))
        .click();
         }
        else if(tabname.equalsIgnoreCase("UPDATES")){
        pageDriver.findElement(By.name(pageprops.getProperty("UPDATES_TAB")))
        .click();
            }*/
    }

    //added 
    catch (Exception e) {
        MintLogger.log(Level.INFO, "Unable to Sign in ");
        e.printStackTrace();
    }
}

From source file:com.qkn.automation.pages.LoginPage.java

public void loginWithInValidCredentials(String email, String password) throws Exception {
    QuickenLogger.log(Level.INFO, "loginWithInValidCredentials");
    WebDriverWait wait = new WebDriverWait(pageDriver, 30);
    pageDriver.findElement(By.name(pageprops.getProperty("SINGUP_BUTTON_LOGINPAGE"))).click();
    Thread.sleep(20000);/*from   w  w  w  . ja  v  a  2 s  .  com*/
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(pageprops.getProperty("LOGIN_USERNAME"))));
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(Keys.CONTROL + "a");
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(Keys.DELETE);
    System.out.println("Before send keys for username");
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(email);
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_PWD"))).sendKeys(Keys.CONTROL + "a");
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_PWD"))).sendKeys(Keys.DELETE);
    //   Thread.sleep(3000);
    System.out.println("Before sendkeys for password");
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_PWD"))).sendKeys(password);
    Thread.sleep(5000);
    pageDriver.navigate().back();

    pageDriver.findElement(By.xpath(pageprops.getProperty("SIGNIN_BTN"))).click();

}

From source file:com.qkn.automation.pages.LoginPage.java

public void navigateToTrusteLogo() throws Exception {

    WebDriverWait wait = new WebDriverWait(pageDriver, 120);
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath(pageprops.getProperty("APP_UPGRADE_POPUP"))));
    pageDriver.findElement(By.xpath(pageprops.getProperty("APP_UPGRADE_POPUP"))).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(pageprops.getProperty("TRUSTE_LOGO"))));
    pageDriver.findElement(By.xpath(pageprops.getProperty("TRUSTE_LOGO"))).click();
    Thread.sleep(12000);//from   www  .j  a v a  2s  .c  o m
    pageDriver.navigate().back();
    Thread.sleep(16000);
}

From source file:com.qkn.automation.pages.LoginPage.java

public void navigateToTrusteLogo_And() throws Exception {

    WebDriverWait wait = new WebDriverWait(pageDriver, 120);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(pageprops.getProperty("TRUSTE_LOGO"))));
    pageDriver.findElement(By.xpath(pageprops.getProperty("TRUSTE_LOGO"))).click();
    Thread.sleep(TestConstants.MINSLEEPTIME);
    pageDriver.navigate().back();// w w  w.j  a  va2s  . co m
    Thread.sleep(TestConstants.MINSLEEPTIME);
}

From source file:com.qkn.automation.pages.LoginPage.java

public void navigateToEndUserLicense() throws Exception {
    WebDriverWait wait = new WebDriverWait(pageDriver, 120);
    //wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(pageprops.getProperty("APP_UPGRADE_POPUP"))));
    //pageDriver.findElement(By.xpath(pageprops.getProperty("APP_UPGRADE_POPUP"))).click();
    Thread.sleep(TestConstants.MINSLEEPTIME);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(pageprops.getProperty("LICENSE"))));
    pageDriver.findElement(By.xpath(pageprops.getProperty("LICENSE"))).click();
    Thread.sleep(TestConstants.MINSLEEPTIME);

    //pageDriver.navigate().back();      
    //Thread.sleep(5000);

}

From source file:com.qkn.automation.pages.LoginPage.java

public void loginViaGetStarted(String email, String password) throws Exception {
    MintLogger.log(Level.INFO, "loginWithInValidCredentials");
    WebDriverWait wait = new WebDriverWait(pageDriver, 30);
    pageDriver.findElement(By.name("Get started")).click();
    Thread.sleep(4000);/*from   w w w. j  a v a 2s .co  m*/
    /*JavascriptExecutor js = (JavascriptExecutor) pageDriver;
    HashMap flickObject = new HashMap();
    flickObject.put("endX", 0);
    flickObject.put("endY", 0);
    flickObject.put("touchCount", 1);
    js.executeScript("mobile: swipe", flickObject);
    Thread.sleep(4000);      */
    pageDriver.findElement(By.name(pageprops.getProperty("SINGUP_BUTTON_GETSTARTEDPAGE"))).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(pageprops.getProperty("LOGIN_USERNAME"))));
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(Keys.CONTROL + "a");
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(Keys.DELETE);
    System.out.println("Before send keys for username");
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_USERNAME"))).sendKeys(email);
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_PWD"))).sendKeys(Keys.CONTROL + "a");
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_PWD"))).sendKeys(Keys.DELETE);
    //      Thread.sleep(3000);
    System.out.println("Before sendkeys for password");
    pageDriver.findElement(By.id(pageprops.getProperty("LOGIN_PWD"))).sendKeys(password);
    Thread.sleep(3000);

    pageDriver.navigate().back();
    Thread.sleep(1000);
    pageDriver.findElement(By.xpath(pageprops.getProperty("SIGNIN_BTN"))).click();

    /*      JavascriptExecutor jse = (JavascriptExecutor) pageDriver;
    jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Go'].tap();");   */
    Thread.sleep(15000);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(pageprops.getProperty("OK_BTN"))));

    if (pageDriver.getPageSource().contains("OK")) {
        pageDriver.findElement(By.name("OK")).click();
    }

    Thread.sleep(13000);
}