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.java.AppTestType_18_11_2015.java

public void NAVIGATETOLISTINGDETAILSPAGE(WebDriver driver) {

    try {/*from w ww .  j av  a  2 s  .  com*/
        //suman
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings");

        Thread.sleep(1000);

        // driver.findElement(By.xpath("(//*[@class='page-dots']/following::a)[1]")).click();//To go to last page of the search results
        //navigating to second page
        driver.findElement(By.linkText("2")).click();

        Thread.sleep(10000);

        List<WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
        System.out.println("number of listings in page: " + listings.size());
        //searching for listing from search result page which may contain events also so excluding events
        for (int i = 1; i < listings.size(); i++) {

            String s1 = listings.get(i).getAttribute("href");
            String s2[] = s1.split("/listing?");
            String s3[] = s2[1].split("&");
            String s4[] = s3[0].split("=");
            String id = s4[1];
            System.out.println("listing id is: " + id);
            System.out.println("listing-" + id);
            String listingText = driver.findElement(By.id("listing-" + id)).getText();
            //String Text[]=listingText.split("\n");
            System.out.println("text in listing is:................... " + listingText);
            if (listingText.contains("MAX BID") || listingText.contains("SIGN IN TO PLACE A BID")
                    || listingText.contains("PLACE A BID")) {
                System.out.println("clicking on listing: " + ((i / 2) + 1));
                listings.get(i).click();
                break;
            }

            i++;

        }

        //waiting upto listing will be loaded
        WebDriverWait wait = new WebDriverWait(driver, 40);
        wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='More from This Seller']")));
        // wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='RETURN TO RESULTS']")));*/

        //Thread.sleep(10000);
        if (driver.findElement(By.xpath("//div[contains(@class,'e1OfferConsole')]")).isDisplayed())
            resultDetails.setFlag(true);
    } catch (Exception e) {
        e.printStackTrace();
        resultDetails.setFlag(false);

    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void LITEUSERREGISTRATION(WebDriver driver, String fieldText, String value) {
    //Lite user registration

    try {//from ww  w  .j  a  v  a  2  s. c o  m
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.get(fieldText);

        String pwd = "Equipment1$";

        String phone = "";
        String Email = "";
        String Fname = value;
        String lname = "Test";
        String validation = "";
        long inc = Math.round(Math.random() * 100000); // generates 5 digit number.
        String ID = "@yahoo.in";

        Random random = new Random();
        long dphone = Math.round(random.nextFloat() * Math.pow(10, 12));

        Email = Fname + lname + inc + ID;

        driver.findElement(By.id("emailaddress")).sendKeys(Email);
        System.out.println(Email);

        phone = Long.toString(dphone);

        driver.findElement(By.id("firstname")).sendKeys(Fname);
        driver.findElement(By.id("lastname")).sendKeys(lname);
        driver.findElement(By.id("phone")).sendKeys(phone);
        driver.findElement(By.id("newPassword")).sendKeys(pwd);
        driver.findElement(By.id("confirmPassword")).sendKeys(pwd);
        driver.findElement(By.xpath("//button[text()='JOIN NOW']")).click();
        Thread.sleep(10000);

        //condition to check the email is already exist
        if (driver.findElements(By.xpath("//*[@class='error-txt']")).size() > 0) {

            //If the email" Email Address already exists"
            if (driver.findElement(By.xpath("//*[@class='error-txt']")).getText()
                    .contains("Email Address already exists in the system")) {
                inc = inc++;
                Email = Fname + lname + inc + "test" + ID;
                driver.findElement(By.id("emailaddress")).clear();
                driver.findElement(By.id("emailaddress")).sendKeys(Email);
                driver.findElement(By.xpath("//button[text()='JOIN NOW']")).click();
            }

            // If the phone number already exist
            if (driver.findElement(By.xpath("//*[@class='error-txt']")).getText()
                    .contains("Another user has the same daytime phone number")) {
                phone = phone + random.nextInt(9);
                driver.findElement(By.id("phone")).clear();
                driver.findElement(By.id("phone")).sendKeys(phone);
                driver.findElement(By.xpath("//button[text()='JOIN NOW']")).click();

            }
        }

        //Verifying that user is successfully registered
        WebDriverWait wait = new WebDriverWait(driver, 35);
        wait.until(ExpectedConditions
                .visibilityOfElementLocated(By.xpath("//*[@class='fa fa-user famember-icon']"))); //verifying the "Activate your membership" icon 
        System.out.println("Successfully Registered user with mail id: " + Email);
        EMAIL = Email;

        resultDetails.setFlag(true);

    }

    catch (Exception e) {
        resultDetails.setFlag(false);

        e.printStackTrace();

    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void APPROVEUSER(WebDriver driver, String fieldText, String value) {
    //To Handle Approve User Popup 
    //FieldText---The User's FullName   and Value-----OK or Cancel
    try {//from w w  w  .j  av a 2 s  . c  o m
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(By.linkText(fieldText)).click();
        Thread.sleep(2000);
        String parentwindow = driver.getWindowHandle();
        if (value.equalsIgnoreCase("OK")) {
            driver.findElement(By.linkText("Approve User")).click();
            Thread.sleep(2000);

            driver.switchTo().alert().accept();

            for (String win : driver.getWindowHandles()) {
                driver.switchTo().window(win);
                try {
                    driver.switchTo().alert().accept();
                } catch (NoAlertPresentException e) {
                    Robot robot = new Robot();
                    robot.keyPress(KeyEvent.VK_SPACE);
                    Thread.sleep(3000);
                }

            }
            Thread.sleep(20000);
            driver.switchTo().window(parentwindow);
            WebDriverWait wait = new WebDriverWait(driver, 20);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id_frm_Email_Address")));
            String Email = driver.findElement(By.id("id_frm_Email_Address")).getText();
            driver.findElement(By.name("email")).sendKeys(EMAIL);
            driver.findElement(By.xpath("//input[@value='Search']")).click();

            String Type = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();
            String Active_Status = driver
                    .findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]")).getText();
            String BStatus = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();
            String SStatus = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();

            if (Type.equalsIgnoreCase("L") && Active_Status.equalsIgnoreCase("Active")
                    && BStatus.equalsIgnoreCase("Approved") && SStatus.equalsIgnoreCase("Approved")) {
                resultDetails.setFlag(true);
            }
        } else if (value.equalsIgnoreCase("CANCEL")) {
            driver.findElement(By.linkText("Approve User")).click();
            Thread.sleep(2000);
            //Robot robot = new Robot();
            // Simulate SPACE KEY press to click on OK button
            //robot.keyPress(KeyEvent.VK_ESCAPE);
            driver.switchTo().alert().dismiss();
            resultDetails.setFlag(true);

        }

    }

    catch (Exception e) {

        e.printStackTrace();
        resultDetails.setFlag(false);
    }
}

From source file:com.java.cukes.CheckoutSteps.java

License:Apache License

@When("^I continue with shipping method$")
public void I_continue_with_shipping_method() throws Throwable {
    new WebDriverWait(driver, 30)
            .until(ExpectedConditions
                    .visibilityOfElementLocated(By.cssSelector("#shipping-method-buttons-container button")))
            .click();/*  ww w  . ja  va 2  s . c  o  m*/

}

From source file:com.java.cukes.CheckoutSteps.java

License:Apache License

@When("^I select payment method as \"([^\"]*)\"$")
public void I_select_payment_method_as(String payment_method) throws Throwable {
    if (payment_method.equals("credit_card")) {
        driver.findElement(By.id("p_method_ccsave")).click();
        new Select(driver.findElement(By.id("ccsave_cc_type"))).selectByVisibleText("Visa");
        driver.findElement(By.id("ccsave_cc_owner")).sendKeys("Opex Software");
        driver.findElement(By.id("ccsave_cc_number")).sendKeys("4111111111111111");
        new Select(driver.findElement(By.id("ccsave_expiration"))).selectByValue("11");
        new Select(driver.findElement(By.id("ccsave_expiration_yr"))).selectByValue("2025");
    } else if (payment_method.equals("cash_on_delivery")) {
        driver.findElement(By.id("p_method_cashondelivery")).click();
    } else if (payment_method.equals("cheque")) {
        driver.findElement(By.id("p_method_checkmo")).click();
    }//from  ww w . ja  v  a2s.co m
    new WebDriverWait(driver, 30).until(
            ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#payment-buttons-container button")))
            .click();
}

From source file:com.java.cukes.CheckoutSteps.java

License:Apache License

@When("^I place the order$")
public void I_place_the_order() throws Throwable {
    new WebDriverWait(driver, 30)
            .until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button.btn-checkout")))
            .click();//www .  ja  va  2s . com
}

From source file:com.korotkin.WebTest.utils.WebPage.java

License:Open Source License

public WebElement getElement(String element) {
    WebDriverWait wait = new WebDriverWait(browser.getDriver(), 10);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(getCssPath(element))));

    return browser.getDriver().findElement(By.cssSelector(getCssPath(element)));
}

From source file:com.liferay.faces.portal.test.integration.demo.PrimeFacesUsersPortletTester.java

License:Open Source License

private ExpectedCondition<Boolean> textPresentInElementClass(String text, String elementXpath) {

    By locator = By.xpath(elementXpath);
    ExpectedCondition<WebElement> elementDisplayed = ExpectedConditions.visibilityOfElementLocated(locator);
    ExpectedCondition<Boolean> textPresentInElementClass = ExpectedConditions.attributeContains(locator,
            "class", text);

    return ExpectedConditions.and(elementDisplayed, textPresentInElementClass);
}

From source file:com.liferay.faces.test.alloy.showcase.datatable.DataTableTesterBase.java

License:Open Source License

/**
 * Determines whether or not the specified text is present in the class attribute of the element targeted by the
 * specified xpath expression.//from   w w w .  j a  v  a  2 s . com
 */
private ExpectedCondition<Boolean> isTextPresentInElementClassAttribute(String text, String elementXpath) {

    By locator = By.xpath(elementXpath);
    ExpectedCondition<WebElement> elementDisplayed = ExpectedConditions.visibilityOfElementLocated(locator);
    ExpectedCondition<Boolean> textPresentInElementClass = ExpectedConditions.attributeContains(locator,
            "class", text);

    return ExpectedConditions.and(elementDisplayed, textPresentInElementClass);
}

From source file:com.liferay.faces.test.selenium.browser.internal.BrowserDriverImpl.java

License:Open Source License

@Override
public void waitForElementDisplayed(String elementXpath) {

    logger.info("Waiting for element {} to be displayed.", elementXpath);
    waitFor(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementXpath)));
    logger.info("Element {} is displayed.", elementXpath);
}