Example usage for org.openqa.selenium WebDriver close

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

Introduction

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

Prototype

void close();

Source Link

Document

Close the current window, quitting the browser if it's the last window currently open.

Usage

From source file:xxx.web.comments.roomfordebate.NYTimesCommentsScraper.java

License:Apache License

/**
 * Downloads the page and rolls out the entire discussion using {@link FirefoxDriver}.
 *
 * @param articleUrl url, e.g. {@code http://www.nytimes.com/roomfordebate/2015/02/04/regulate-internet-providers/the-internet-is-back-to-solid-regulatory-ground}
 * @return generated HTML code of the entire page
 * @throws InterruptedException//from   ww  w  .  jav  a2  s .co m
 */
public String readHTML(String articleUrl) throws InterruptedException {
    // load the url
    WebDriver driver = new FirefoxDriver();
    driver.get(articleUrl);

    // roll-out the entire discussion
    List<WebElement> commentsExpandElements;
    do {
        commentsExpandElements = driver.findElements(By.cssSelector("div.comments-expand"));

        // click on each of them
        for (WebElement commentsExpandElement : commentsExpandElements) {
            // only if visible & enabled
            if (commentsExpandElement.isDisplayed() && commentsExpandElement.isEnabled()) {
                commentsExpandElement.click();

                // give it some time to load new comments
                Thread.sleep(3000);
            }
        }
    }
    // until there is one remaining that doesn't do anything...
    while (commentsExpandElements.size() > 1);

    // get the html
    String result = driver.getPageSource();

    // close firefox
    driver.close();

    return result;
}

From source file:zz.pseas.ghost.browser.BrowserFactory.java

License:Apache License

public static void main(String[] args) {
    WebDriver fireFox = BrowserFactory.getChrome();
    fireFox.close();
}