Example usage for org.openqa.selenium WebDriver quit

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

Introduction

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

Prototype

void quit();

Source Link

Document

Quits this driver, closing every associated window.

Usage

From source file:com.zhao.crawler.jd.LoginContentList.java

License:Open Source License

@Override
public void addGoods(Page page) {
    WebDriver driver = null;
    try {/*from w w w  . j  av a  2 s  .  c o  m*/
        System.out.println(page.getResponse().getContent());

        String selector = "root";

        //li.premium-pricecube
        driver = PageUtils.getWebDriver(page);
        List<WebElement> eles = driver.findElements(By.cssSelector(selector));

        if (!eles.isEmpty()) {
            for (WebElement ele : eles) {

                System.out.println(" ### " + ele.getText());
                //               // ?
                //               g.setUrl(ele.findElement(By.className("p-name"))
                //                     .findElement(By.tagName("a"))
                //                     .getAttribute("href"));
                //               // 
                //               String commitStr = ele
                //                     .findElement(By.className("p-commit"))
                //                     .findElement(By.tagName("a"))
                //                     .getText();
                //               if (Tools.notEmpty(commitStr)) {
                //                  commitStr ="100";
                //                  g.setCommit(Integer.parseInt(commitStr));
                //               } else {
                //                  g.setCommit(-1);
                //               }

            }
        } else {
            System.out.println("else is empty");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:com.zhao.crawler.jd.QunaerGoodsList.java

License:Open Source License

@Override
public void addGoods(Page page) {
    WebDriver driver = null;
    try {/* w  w  w . j  a v a2s . c  o  m*/

        String selector = "html";
        //li.premium-pricecube
        driver = PageUtils.getWebDriver(page);
        List<WebElement> eles = driver.findElements(By.cssSelector(selector));
        if (!eles.isEmpty()) {
            for (WebElement ele : eles) {
                Goods g = new Goods();
                g.setPlatform(Platform.Qunaer);// ?
                // 
                //               String priceStr = ele.findElement(By.className("p-price"))
                //                     .findElement(By.className("J_price"))
                //                     .findElement(By.tagName("i"))
                //                     .getText();
                //                  if (Tools.notEmpty(priceStr)) {
                //                  g.setPrice(Float.parseFloat(priceStr));
                //               } else {
                //                  g.setPrice(-1f);
                //               }
                // ???
                g.setName(ele.getText());
                //               // ?
                //               g.setUrl(ele.findElement(By.className("p-name"))
                //                     .findElement(By.tagName("a"))
                //                     .getAttribute("href"));
                //               // 
                //               String commitStr = ele
                //                     .findElement(By.className("p-commit"))
                //                     .findElement(By.tagName("a"))
                //                     .getText();
                //               if (Tools.notEmpty(commitStr)) {
                //                  commitStr ="100";
                //                  g.setCommit(Integer.parseInt(commitStr));
                //               } else {
                //                  g.setCommit(-1);
                //               }

                add(g);
            }
        } else {
            System.out.println("else is empty");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:conexiones.HTMLData.java

private static int dataContaduria(Expediente exp, Estados estado) {
    WebDriver driver = new HtmlUnitDriver();
    try {//w  ww . j a  v a 2s . co  m
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get(URL_CONTADURIA);
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbCaratula")).clear();
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbCaratula")).sendKeys(exp.getCaratula());
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbNumero")).clear();
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbNumero")).sendKeys(exp.getNumero());
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbAnio")).clear();
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbAnio")).sendKeys(exp.getAnio());
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbAlcance")).clear();
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_tbAlcance")).sendKeys(exp.getAlcance());
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_btnConsultar")).submit();
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.NANOSECONDS);
        try {
            estado.setEstado(driver.findElement(By.id("lblJur")).getText());
            estado.setFechaCon(driver.findElement(By.id("lblEgreFecha")).getText());
            estado.setFechaE(estado.getFechaCon());
            estado.setPagina("");
            return EXP_ENCONTRADO;
        } catch (NoSuchElementException e) {
            try { //el expediente esta en contaduria.
                estado.setEstado(
                        driver.findElement(By.id("ctl00_ContentPlaceHolder1_lblOficinaActual")).getText());
                estado.setFechaR(
                        driver.findElement(By.id("ctl00_ContentPlaceHolder1_lblFechaIngreso")).getText());
                estado.setPagina("Contaduria");
                return EXP_ENCONTRADO;
            } catch (NoSuchElementException ex) {
                return EXP_NO_ENCONTRADO; //No se encontro el expediente
            }
        }
    } catch (Exception ex) {
        return ERROR_PAGINA; //No es posible acceder a la pagina
    } finally {
        driver.quit();
    }
}

From source file:crawl.CrawlThread.java

License:Open Source License

@Override
public void run() {
    WebDriver driver = new FirefoxDriver(); // The Firefox driver supports javascript 
    Autenticate.perform(driver, fb_email, fb_password);
    try {/*from   w  w w .  ja v a 2  s. c  o m*/
        Thread.sleep(Globals.TIME_TO_LOGIN_IN_FB_MS);
    } catch (Exception ex) {
        System.out.println("InterruptedException in crawl.run()");
        ex.printStackTrace();
        System.exit(-1);
    }
    for (String post_id : post_list) {
        //OPEN NEW TAB
        WebElement body = driver.findElement(By.tagName("body"));
        body.sendKeys(Keys.CONTROL + "t");
        Tree post = new Tree(post_id, GLOBALS);
        boolean result = post.crawl(driver);
        if (result) {
            post.prune();
            post.print();
            post.printEdgeList();
        } else {
            body.sendKeys(Keys.CONTROL + "w");
        }
        //SWITCH TAB
        ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
        driver.switchTo().window(tabs.get(tabs.size() - 1));
    }
    driver.quit();
}

From source file:cuenen.raymond.svgplot.TestSuiteClass.java

License:CDDL license

@AfterSuite(alwaysRun = true)
public static void stopSelenium() {
    for (WebDriver driver : DRIVERS) {
        StringBuilder sb = new StringBuilder("Tested ");
        if (driver instanceof HasCapabilities) {
            Capabilities caps = ((HasCapabilities) driver).getCapabilities();
            if (caps.getBrowserName().equals("opera")) {
                /* The OperaDriver has no support for JavaScript alert/popup dialogues. */
                sb.append("partly ");
            }/*from www  . ja  va 2s .  co m*/
            sb.append("with ").append(caps.getBrowserName());
            sb.append(" ").append(caps.getVersion());
            sb.append(" on ").append(caps.getPlatform());
        } else {
            sb.append("with ").append(driver);
        }
        Reporter.log(sb.toString(), true);
        driver.quit();
    }
}

From source file:Data.Database.java

public void addTeams() throws InterruptedException, FileNotFoundException {
    Scanner fileScanner = new Scanner(new File("login.txt"));
    String username = fileScanner.nextLine();
    String password = fileScanner.nextLine();

    WebDriver firefoxDriver = new FirefoxDriver();

    //Open the url which we want in firefox
    firefoxDriver.get("http://www.fantrax.com/fantasy/teamRosterChart.go?leagueId=ntokropui8nbbjt1");
    WebElement link;//from  w  ww .j av a 2s  .  c o m
    link = firefoxDriver.findElement(By.id("loginZone"));
    link.click();
    WebElement input;
    input = firefoxDriver.findElement(By.id("j_username"));
    input.sendKeys(username);
    input = firefoxDriver.findElement(By.id("realPassword"));
    input.sendKeys(password);
    input.sendKeys(Keys.RETURN);

    Thread.sleep(2000);
    firefoxDriver.get("http://www.fantrax.com/fantasy/teamRosterChart.go?leagueId=ntokropui8nbbjt1");
    String data = firefoxDriver.getPageSource();

    data = data.substring(data.indexOf("<table class=\"fantTable rosterChart\">"));
    data = data.substring(0, data.indexOf("</tbody>"));
    String[] temp = data.split("<td class=\"team leftCol\">");
    //System.out.println(temp[1]);

    for (int i = 1; i < temp.length; i++) {
        Team t = new Team();
        t.fillTeam(years, lookup, temp[i]);
        fh_teams.add(t);
        t.getTotals();
        t.printAverages();
    }

    firefoxDriver.quit();
}

From source file:db.Db.java

public static void main(String[] args) throws InterruptedException, Exception {
    // TODO code application logic here

    //SETUP/*from  w ww . j a  v a2 s  . c om*/
    WebDriver driver;
    String referralUrl, accounts[][];
    String mSuffix = new String();

    double space = 0, nAccounts;
    int needAccounts, creAccounts, f;
    StringBuffer verificationErrors = new StringBuffer();
    driver = new FirefoxDriver();
    //        driver = new HtmlUnitDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    referralUrl = "https://www.dropbox.com/referrals/NTM2OTAyMjIyMjk?src=global9";
    mSuffix = "@gmail.com";
    space = 16.250;
    space = (Math.floor(space * 2) / 2); //trunk number to .0 or .5

    needAccounts = (int) ((18 - space) * 2); //number of accounts needed
    creAccounts = 0; //number of accounts created
    accounts = new String[needAccounts][4]; //accounts credentials matrix

    //GENERATE ACCOUNTS

    for (f = 0; f < accounts.length; f++)
        genAccount(accounts, mSuffix, f);

    //REGISTER
    int regAttempts = 0;
    System.out.print("Registering accounts => ");
    for (f = 0; f < accounts.length; f++) {
        while (!regAccount(accounts, referralUrl, f, driver) && regAttempts < 3) {

            regAttempts++;
            genAccount(accounts, mSuffix, f);
        }
        if (regAttempts < 3)
            creAccounts++;
        else
            System.out.println("Registration failed 3 consecutive times. Aborting");

    } //end for

    if (creAccounts == needAccounts)
        System.out.println("\n" + creAccounts + " DROPBOX ACCOUNTS CREATED SUCCESFULLY!!  :D :D");

    //TEARDOWN
    driver.quit();

}

From source file:de.knowwe.uitest.haddock.BMIHaddockUITest.java

License:Open Source License

public BMIHaddockUITest(String browser, Platform os) throws IOException, InterruptedException {
    super();// w  ww.  java2s.c om

    this.browser = browser;
    this.os = os;

    UITestConfig config = new UITestConfig(browser, os);
    if (drivers.get(config) != null) {
        driver = drivers.get(config);
    } else {
        for (WebDriver d : drivers.values()) {
            d.quit();
        }
        driver = UITestUtils.setUp(browser, BMIHaddockUITest.class.getSimpleName(), os, TEMPLATE, getTestName(),
                devMode);
        drivers.put(config, driver);
    }
}

From source file:de.knowwe.uitest.haddock.DiaFluxHaddockUITest.java

License:Open Source License

public DiaFluxHaddockUITest(String browser, Platform os) throws IOException, InterruptedException {
    super();/* w  w w. ja  va  2  s.c  o  m*/

    this.browser = browser;
    this.os = os;

    UITestConfig config = new UITestConfig(browser, os);
    if (drivers.get(config) != null) {
        driver = drivers.get(config);
    } else {
        for (WebDriver d : drivers.values()) {
            d.quit();
        }
        driver = UITestUtils.setUp(browser, BMIHaddockUITest.class.getSimpleName(), os, TEMPLATE, getTestName(),
                devMode);
        drivers.put(config, driver);
    }
}

From source file:de.knowwe.uitest.haddock.FormatterHaddockUITest.java

License:Open Source License

public FormatterHaddockUITest(String browser, Platform os) throws IOException, InterruptedException {
    super();/*from w  w  w .j a  v a2 s .c o m*/

    this.browser = browser;
    this.os = os;

    UITestConfig config = new UITestConfig(browser, os);
    if (drivers.get(config) != null) {
        driver = drivers.get(config);
    } else {
        for (WebDriver d : drivers.values()) {
            d.quit();
        }
        driver = UITestUtils.setUp(browser, BMIHaddockUITest.class.getSimpleName(), os, TEMPLATE, getTestName(),
                devMode);
        drivers.put(config, driver);
    }
}