Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

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

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:com.grupo2s.demo.event2s.CredencialesEventoTest.java

@Before
public void setUp() throws Exception {
    WebDriver driver = new FirefoxDriver();
    String baseUrl = "http://demo.event2s.com/";
    wait = new WebDriverWait(driver, 10);
    selenium = new WebDriverBackedSelenium(driver, baseUrl);
}

From source file:com.grupo2s.demo.event2s.ReservarEventoEmbebidoTest.java

@Before
public void setUp() throws Exception {
    driver = new FirefoxDriver();
    String baseUrl = "http://demo.event2s.com/";
    wait = new WebDriverWait(driver, 10);
    selenium = new WebDriverBackedSelenium(driver, baseUrl);
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

public boolean login() {
    openSite(LOGIN_URL);/* w w  w .ja  v  a  2 s .com*/
    webDriver.findElement(By.id("login-email")).sendKeys(username);
    webDriver.findElement(By.id("login-password")).sendKeys(password);
    webDriver.findElement(By.className("login-form-submit")).findElement(By.tagName("button")).click();

    //        waitForSeconds(10);

    try {
        // if found then return true, otherwise return false
        (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                .until(ExpectedConditions.presenceOfElementLocated(By.className("item-sign-out")));
        //            webDriver.findElement(By.className("item-sign-out")); 
    } catch (Exception ex) {
        System.out.println(ex);
        return false;
    }

    return true;
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

public void updateGumtreeModel(List<Gumtree> gumtrees) {
    List<Gumtree> gumtreesNeedToWrite = new ArrayList<>();
    int count = 0;
    int totalGumtreeLength = gumtrees.size();
    for (int i = 0; i < totalGumtreeLength; i++) {
        //            ad-attributes
        Gumtree gumtree = gumtrees.get(i);
        try {//from  ww  w  .j a  v a 2 s .co  m
            openSite(gumtree.getUrl());
            waitForPageToLoad();

            String content = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                    .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//meta[@name='WT.cg_s']")))
                    .getAttribute("content").toLowerCase();

            String type = content.contains("sale") ? "sale" : "rent";
            gumtree.setType(type);

            String saleRentId = "forsaleby_s-wrapper";
            if (type.equals("rent")) {
                saleRentId = "forrentby_s-wrapper";
            }

            String saleRentBy = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                    .until(ExpectedConditions.presenceOfElementLocated(
                            By.xpath("//div[@id='ad-attributes']/dl[contains(@id, '" + saleRentId + "')]/dd")))
                    .getText().trim();

            System.out.append("===Sale/Rent by: " + saleRentBy);

            if (!"owner".equalsIgnoreCase(saleRentBy)) {
                continue;
            }

            String name = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                    .until(ExpectedConditions.presenceOfElementLocated(
                            By.xpath("//div[@id='reply-form']//div[@class='reply-form-name']/a")))
                    .getText().trim();

            gumtree.setName(name);
            gumtreesNeedToWrite.add(gumtree);

            if ((i > 0 && (count % NUMBER_OF_LINE_TO_SERIALIZE) == 0) || (i == totalGumtreeLength - 1)) {
                writeToCsvFile(gumtreesNeedToWrite, fileName);
                gumtreesNeedToWrite.clear();
            }

        } catch (TimeoutException ex) {
            gumtree.setNotes("TIME_OUT");
            System.out.print(ex.getMessage());
        }
    }
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

public void scrapeWithClick(List<Gumtree> gumtrees, String url) {

    openSite(url);/*from   w w w .jav a2s. co  m*/
    waitForPageToLoad();

    do {
        List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, getTimeout()))
                .until(ExpectedConditions.presenceOfAllElementsLocatedBy(
                        By.xpath("//ul[@id='srchrslt-adtable']/li//h6[@class='rs-ad-title']/a")));

        for (WebElement ad : gumtreeAds) {
            //                String adUrl = (new WebDriverWait(this.webDriver, 15))
            //            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a"))).getAttribute("href");
            //                String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href");
            String adUrl = ad.getAttribute("href");
            Gumtree gumtree = new Gumtree();
            gumtree.setUrl(adUrl);
            gumtrees.add(gumtree);
        }

        List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']"));
        if (nextElements.isEmpty()) { //  no more next page
            break;
        }

        nextElements.get(0).click();
        try {
            Thread.sleep(5000);

        } catch (InterruptedException ex) {
            Logger.getLogger(GumtreeScraper.class.getName()).log(Level.SEVERE, null, ex);
        }

    } while (true);
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

public void scrape(List<Gumtree> gumtrees, String url) {

    // get total page
    int totalPage = getTotalPage(url);

    for (int i = 1; i <= totalPage; i++) {

        String newUrl = buildPageUrl(url, i);
        //            openSiteWithoutTimeout(newUrl);
        openSite(newUrl);/*from   ww  w .  ja v a  2 s.  c  o  m*/
        waitForPageToLoad();

        if (i == 1) {
            try {
                Thread.sleep(20 * 1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(GumtreeScraper.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        //            List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, 15))
        //            .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//ul[@id='srchrslt-adtable']/li")));

        List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                .until(ExpectedConditions.presenceOfAllElementsLocatedBy(
                        By.xpath("//ul[@id='srchrslt-adtable']/li//h6[@class='rs-ad-title']/a")));

        for (WebElement ad : gumtreeAds) {
            //               (new WebDriverWait(this.webDriver, 15))
            //            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a")));

            try {
                //                    String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href");
                String adUrl = ad.getAttribute("href");
                Gumtree gumtree = new Gumtree();
                gumtree.setUrl(adUrl);
                gumtrees.add(gumtree);
            } catch (StaleElementReferenceException ex) {
                ex.printStackTrace();
                String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href");
                Gumtree gumtree = new Gumtree();
                gumtree.setUrl(adUrl);
                gumtrees.add(gumtree);
            }
        }

        //            List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']"));
        //            if (nextElements.isEmpty()) { //  no more next page
        //                break;
        //            }
        //
        //            nextElements.get(0).click();
    }

    //        List<WebElement> lastPageElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn last']"));
    //        if (lastPageElements.isEmpty()) { // 1 page only
    //            return;
    //        }
    //                
    //        do {
    //            List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, 15))
    //            .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//ul[@id='srchrslt-adtable']/li")));
    //                      
    //            for (WebElement ad : gumtreeAds) {
    //                String adUrl = (new WebDriverWait(this.webDriver, 15))
    //            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a"))).getAttribute("href");
    ////                String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href");
    //                Gumtree gumtree = new Gumtree();
    //                gumtree.setUrl(adUrl);
    //                gumtrees.add(gumtree);
    //            }
    //
    //            List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']"));
    //            if (nextElements.isEmpty()) { //  no more next page
    //                break;
    //            }
    //
    //            nextElements.get(0).click();
    //
    ////        scrape(gumtrees, nextPageUrl);
    //        
    //        } while(true);
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

private int getTotalPage(String url) {
    openSiteWithoutTimeout(url);//  w ww .  jav  a 2s. c o  m
    String lastPageUrl = (new WebDriverWait(this.webDriver, 15))
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@class='rs-paginator-btn last']")))
            .getAttribute("href");

    // http://www.gumtree.com.au/s-land-for-sale/page-109/c20031
    String findString = "/page-";
    int indexPage = lastPageUrl.indexOf(findString);
    int lastIndexOfSlash = lastPageUrl.lastIndexOf("/");
    String totalPageStr = lastPageUrl.substring(indexPage + findString.length(), lastIndexOfSlash);
    return Integer.parseInt(totalPageStr);
}

From source file:com.gwtplatform.carstore.cucumber.application.BasePage.java

License:Apache License

private WebDriverWait webDriverWait() {
    return new WebDriverWait(webDriver, TestParameters.TIME_OUT_IN_SECONDS);
}

From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java

License:Apache License

/**
 * Perform click action.// w w  w .ja  v  a2  s  .c om
 *
 * @param clickElement
 *            the click element
 * @param waitDelay
 *            the wait delay
 * @throws InterruptedException
 *             the interrupted exception
 */
private void performClickAction(final WebElement clickElement, final int waitDelay)
        throws InterruptedException {
    assertNotNull(clickElement);
    waitUntilDisplayed(clickElement);

    if (browser.contains("htmlunit")) {
        clickElement.click();
    } else {

        final WebDriverWait wait = new WebDriverWait(driver, WAIT_FOR_PAGE_ELEMENT);
        wait.until(ExpectedConditions.visibilityOf(clickElement));

        action.clickAndHold(clickElement).release().perform();

        //         action.moveToElement(clickElement);
        //         //action.doubleClick(clickElement);

        //         ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", clickElement);
        //         JavascriptExecutor js = (JavascriptExecutor) driver;
        //         js.executeScript("arguments[0].click();", clickElement);

    }
    waitForBrowser(waitDelay);
    grabScreenshot(driver);

}

From source file:com.hotwire.selenium.angular.AngularFareFinderFragment.java

License:Open Source License

/**
 * This chooses the first item from the dropdown that contains the destination string.
 *
 * @param destination//w  w w . j  ava2  s .c o  m
 */
private void selectDestinationFromDropdown(String destination) {
    try {
        new WebDriverWait(getWebDriver(), 3)
                .until(new VisibilityOf(By.cssSelector(".site-content ul.dropdown-menu")));
    } catch (TimeoutException e) {
        LOGGER.info("AutoComplete menu didn't show for " + destination + " destination.");
        return;
    }
    List<WebElement> locations = getWebDriver()
            .findElements(By.cssSelector(".site-content ul.dropdown-menu li a"));
    for (WebElement element : locations) {
        if (element.getText().trim().contains(destination)) {
            element.click();
            return;
        }
    }
    this.destination.sendKeys(Keys.ESCAPE);
}