Example usage for org.openqa.selenium WebDriver findElements

List of usage examples for org.openqa.selenium WebDriver findElements

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver findElements.

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current page using the given mechanism.

Usage

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public static void waitForTripWatcherVisibility(final WebDriver webdriver) {
    new WebDriverWait(webdriver, 20).until(new ExpectedCondition<Boolean>() {
        @Override//from   www .j  a va2  s.  co m
        public Boolean apply(WebDriver input) {
            new HotelResultsPage(input);
            for (WebElement element : input.findElements(By.cssSelector(TRIP_WATCHER_LAYER))) {
                if (element.isDisplayed()) {
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:com.hotwire.selenium.mobile.search.HotelSearchFragment.java

License:Open Source License

public static void waitForAutoCompleteListToChange(final WebDriver webdriver,
        final List<WebElement> startList) {
    new WebDriverWait(webdriver, 5).until(new ExpectedCondition<Boolean>() {
        @Override/* w  w  w  .j  a  v  a2s .  c o  m*/
        public Boolean apply(WebDriver input) {
            List<WebElement> currentList = webdriver
                    .findElements(By.cssSelector(DESTINATION_LAYER_LOCATIONS_LIST));
            LOGGER.info("Waiting for AutoComplete list to change.");
            if (startList.containsAll(currentList) && currentList.containsAll(startList)
                    && startList.size() == currentList.size()) {
                return false;
            }
            LOGGER.info("AutoComplete list changed.");
            return true;
        }
    });
}

From source file:com.hotwire.test.steps.job.JobModelImpl.java

License:Open Source License

@Override
public void waitForLoadingLayer() {
    boolean loadingLayerVisible;
    By loadingImage = By.cssSelector("img[src*='hotel_search_loadingLayer.gif']");
    WebDriver wd = getWebdriverInstance();
    waitForElementVisible(wd, loadingImage, true, 20);
    waitForElementVisible(wd, loadingImage, false, 20);
    List<WebElement> elements = wd.findElements(loadingImage);
    loadingLayerVisible = elements.isEmpty();
    assertThat(loadingLayerVisible).as("loading layer was visible; shouldn't be visible").isTrue();

}

From source file:com.htm.ManageTest.java

License:Open Source License

public static void testDropDown(WebDriver driver) {
        String[] hrefArray = { "manual", "auto", "import", "autostack", "custom" };
        List<WebElement> anchors = driver.findElements(By.cssSelector("div div ul li a"));
        Assert.assertTrue(hrefArray.length == anchors.size());
        for (int i = 0; i < anchors.size(); i++) {
            String hrefString = anchors.get(i).getAttribute("href").toString();
            Assert.assertTrue(hrefString.contains(hrefArray[i]), String.format("%s not present", hrefString));
        }//from   w ww .  j a  v  a  2 s  .c o m
    }

From source file:com.htm.WelcomeTest.java

License:Open Source License

public static void welcomeDropdown(WebDriver driver) {
        String welcomedropDown[] = new String[] { "ap-northeast-1: Asia Pacific (Tokyo)",
                "ap-southeast-1: Asia Pacific (Singapore)", "ap-southeast-2: Asia Pacific (Sydney)",
                "eu-west-1: EU (Ireland)", "sa-east-1: South America (Sao Paulo)",
                "us-east-1: US East (Northern Virginia)", "us-west-1: US West (Northern California)",
                "us-west-2: US West (Oregon)" };
        int ddlength = welcomedropDown.length;
        List<WebElement> regionName = driver.findElements(By.xpath("//select//option"));
        Assert.assertTrue(ddlength == regionName.size());
        for (int locaterIndex = 0; locaterIndex < ddlength; locaterIndex++) {
            String xpathString = String.format("//select//option[%d]", locaterIndex + 1);
            String val = driver.findElement(By.xpath(xpathString)).getText();
            Assert.assertTrue(welcomedropDown[locaterIndex].equalsIgnoreCase(val));
        }//ww w  .  java 2 s .  c  o m
    }

From source file:com.htmlhifive.pitalium.core.model.SelectorType.java

License:Apache License

/**
 * ?????????//from w w  w  .  ja  v a 2s. co  m
 * 
 * @param driver WebDriver?
 * @param selector 
 * @return ?????
 */
public List<WebElement> findElements(WebDriver driver, String selector) {
    return driver.findElements(by(selector));
}

From source file:com.ibm.watson.app.qaclassifier.selenium.CommonFunctions.java

License:Open Source License

private static void waitForAnswer(WebDriver driver, final String questionText) {
    // We know that an answer has been returned when the answer tag has a child element.
    new WebDriverWait(driver, 10).until(new Predicate<WebDriver>() {
        @Override// w  ww  . j a va2s .c om
        public boolean apply(WebDriver input) {
            // If we're given a stale element exception, just return false and let it grab the correct
            // text during the next polling interval
            try {
                boolean answerFound = input.findElements(By.xpath("//answer/*")).size() > 0;
                String foundText = input.findElement(By.id("questionText")).getText();
                boolean questionTextFound = foundText.contains(questionText);

                return answerFound && questionTextFound;
            } catch (StaleElementReferenceException e) {
                return false;
            }
        }
    });
}

From source file:com.java.AppTestType_18_11_2015.java

public void LOADNEWUSERREG(WebDriver driver, String fieldText, String value) {

    try {//from  w w  w .j  a  v  a  2 s .  c om
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.get(fieldText);
        int num = Integer.parseInt(value);
        int i;

        for (i = 0; i <= num; i++) {

            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            driver.get(fieldText);

            String pwd = "Equipment1$";

            String phone = "";
            String Email = "";
            String Fname = "Load";
            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();

            //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, 20);
            wait.until(ExpectedConditions
                    .visibilityOfElementLocated(By.xpath("//*[@class='fa fa-user famember-icon']"))); //verifying the "Activate your membership" icon 
            System.out.println("Successfully Registered");

            System.out.println(Email);
        }

        resultDetails.setFlag(true);
    } catch (Exception e) {
        e.printStackTrace();

        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void COMPARE(WebDriver driver, String action) {

    List<WebElement> results = driver.findElements(By.id("results"));

    for (WebElement rel : results) {

        rel.getText();/*from   w  ww.  j a  va  2 s .  c  o  m*/

        //System.out.println(rel.getText());

        WebElement compare = driver.findElement(By.className("compare"));

        keywords comparecheck = keywords.valueOf(action.toUpperCase());

        switch (comparecheck) {

        case fposition:

            try {

                if (compare.isDisplayed()) {

                    driver.findElement(By.cssSelector("input.selectoff")).click();
                }

            } catch (Exception e) {

            }

            break;

        case sposition:

            break;

        case tposition:

            break;

        }

    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void MAXINEVENTPAGE(WebDriver driver) {

    try {/*  www.  j a v  a  2 s  .  c  o m*/

        List<WebElement> listings = driver.findElements(By.cssSelector("a[href*='/event?eventid']"));

        Random r = new Random();
        int randomValue = r.nextInt(listings.size()); //Getting a random value that is between 0 and (list's size)-1
        listings.get(randomValue).click();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        String offer = driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div/span")).getText();

        System.out.println(offer);

        String Max = offer.substring(1, offer.length() - 2);

        if (Max.indexOf(',') > -1) {

            System.out.println("Field has comma");
            String convert = Max.replace(",", "");

            String dot = convert.replace(".", "");
            int mymaxoffer = Integer.parseInt(dot);
            int finaladding = add + mymaxoffer;

            String convadd = String.valueOf(finaladding);

            System.out.println(convadd);

            driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div[3]/input")).sendKeys(convadd);

            driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div[3]/button")).click();
            Thread.sleep(10000);

            driver.findElement(By.xpath("//div[5]/div[3]/input")).sendKeys(convadd);
            Thread.sleep(10000);
            driver.findElement(By.xpath("//div[5]/div[3]/button")).click();
            Thread.sleep(10000);

            boolean isPresent = driver.findElement(By.cssSelector("input.jsTermsAgree")).isDisplayed();

            if (isPresent == true) {

                driver.findElement(By.cssSelector("input.jsTermsAgree")).click();
                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);
            }

            else {

                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);

            }

        }

        else {

            System.out.println("field does not have comma");

            String mydot = Max.replace(".", "");

            System.out.println(mydot);

            int mymaxoffer = Integer.parseInt(mydot);
            int finaladding = add + mymaxoffer;

            String convadd = String.valueOf(finaladding);

            driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div[3]/input")).sendKeys(convadd);

            driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div[3]/button")).click();
            Thread.sleep(10000);

            driver.findElement(By.xpath("//div[5]/div[3]/input")).sendKeys(convadd);

            driver.findElement(By.xpath("//div[5]/div[3]/button")).click();
            Thread.sleep(10000);

            boolean isPresent = driver.findElement(By.cssSelector("input.jsTermsAgree")).isDisplayed();

            if (isPresent == true) {

                driver.findElement(By.cssSelector("input.jsTermsAgree")).click();
                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);
            }

            driver.findElement(By.xpath("//li[9]/button")).click();
            Thread.sleep(10000);

        }

        resultDetails.setFlag(true);

    } catch (Exception e) {

        resultDetails.setFlag(false);
        resultDetails.setErrorMessage("Listing is not available or Closed");
    }

}