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:Scrapper.Udemy.java

public void Getter_beginner(String Key) {

    c_model mod = new c_model();
    // c_model[] r_model = new c_model[40];
    int q = 0;/*from   ww  w  . ja  v a  2 s  . c  o m*/
    System.setProperty("webdriver.gecko.driver", "/usr/geckodriver");
    WebDriver dr = new FirefoxDriver();
    dr.get("https://www.udemy.com/courses/search/?ref=home&src=ukw&q=" + Key
            + "&instructionalLevel=beginner&price=price-free");
    dr.manage().window().maximize();
    dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> list = dr.findElements(By.className("card__inner"));
    java.util.Iterator<WebElement> i = list.iterator();
    while (i.hasNext()) {
        if (q > 40) {
            break;
        }

        WebElement row = i.next();

        mod.setC_name(row.findElement(By.className("card__title")).getText());
        mod.setC_src(row.findElement(By.className("card__title")).getAttribute("href"));
        mod.setC_img_src(row.findElement(By.className("card__image")).getAttribute("src"));
        mod.setC_insta(row.findElement(By.className("card__instructor-inner")).getText());
        mod.setType(Key);
        mod.setLevel("1");
        in.insert_course(mod);
        //  r_model[q++] = mod;
    }
    dr.quit();
    // return r_model;
}

From source file:Scrapper.Udemy.java

public void Getter_intermediate(String Key) {

    c_model mod = new c_model();
    //c_model[] r_model = new c_model[40];
    int q = 0;//from   ww w .  j  av  a2s.  com
    System.setProperty("webdriver.gecko.driver", "/usr/geckodriver");
    WebDriver dr = new FirefoxDriver();
    dr.get("https://www.udemy.com/courses/search/?ref=home&src=ukw&q=" + Key
            + "&instructionalLevel=intermediate&price=price-free");
    dr.manage().window().maximize();
    dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> list = dr.findElements(By.className("card__inner"));
    java.util.Iterator<WebElement> i = list.iterator();
    while (i.hasNext()) {
        if (q > 40) {
            break;
        }

        WebElement row = i.next();

        mod.setC_name(row.findElement(By.className("card__title")).getText());
        mod.setC_src(row.findElement(By.className("card__title")).getAttribute("href"));
        mod.setC_img_src(row.findElement(By.className("card__image")).getAttribute("src"));
        mod.setC_insta(row.findElement(By.className("card__instructor-inner")).getText());
        mod.setType(Key);
        mod.setLevel("2");
        in.insert_course(mod);
        ///r_model[q++] = mod;
    }
    dr.quit();
    //return r_model;
}

From source file:Scrapper.Udemy.java

public void Getter_expert(String Key) {

    c_model mod = new c_model();
    // c_model[] r_model = new c_model[40];
    int q = 0;//  ww w. j  a v  a 2  s. c  o  m
    System.setProperty("webdriver.gecko.driver", "/usr/geckodriver");
    WebDriver dr = new FirefoxDriver();
    dr.get("https://www.udemy.com/courses/search/?ref=home&src=ukw&q=" + Key
            + "&instructionalLevel=expert&price=price-free");
    dr.manage().window().maximize();
    dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> list = dr.findElements(By.className("card__inner"));
    java.util.Iterator<WebElement> i = list.iterator();
    while (i.hasNext()) {
        if (q > 40) {
            break;
        }

        WebElement row = i.next();

        mod.setC_name(row.findElement(By.className("card__title")).getText());
        mod.setC_src(row.findElement(By.className("card__title")).getAttribute("href"));
        mod.setC_img_src(row.findElement(By.className("card__image")).getAttribute("src"));
        mod.setC_insta(row.findElement(By.className("card__instructor-inner")).getText());
        mod.setType(Key);
        mod.setLevel("3");
        in.insert_course(mod);
        // r_model[q++] = mod;
    }
    dr.quit();
    //  return r_model;
}

From source file:selenium.EventsPageIT.java

@Test
public void testSimple() throws Exception {

    WebDriver driver = new InternetExplorerDriver();

    driver.get("http://localhost:8080/eventlist/events.jsp");

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override/* www.j  av  a 2  s  . com*/
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("Events");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:selenium.UploadPageIT.java

@Test
public void testSimple() throws Exception {

    WebDriver driver = new InternetExplorerDriver();

    driver.get("http://localhost:8080/eventlist/upload.jsp");

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override/*from   w w w . j  a v a 2s  .c  o m*/
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("Upload JSON Data");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:seleniumsample.SeleniumSample.java

public static void InvokeSelenium(String pstrSearchkeyword) {
    try {// ww w.  j a v  a 2s .c  o m
        WebDriver driver = new HtmlUnitDriver();
        driver.get("http://www.google.com");
        WebElement lobjelement = driver.findElement(By.name("q"));
        lobjelement.sendKeys(pstrSearchkeyword);
        lobjelement.submit();
        char[] lobjBuffer = driver.getPageSource().toCharArray();
        //lobjfilewriter.write(lobjBuffer);
        //String lstrpath=file.getAbsolutePath();
        //System.out.println(mstrSearchkeyword+" File successfully created at!! "+lstrpath);
        WriteTheContentToTextFile(lobjBuffer, pstrSearchkeyword);
        driver.quit();

    } catch (Exception lobjException) {
        Logger.getLogger(SeleniumSample.class.getName()).log(Level.SEVERE, null, lobjException);

    }
}

From source file:selenium_webdriver_test_01.Selenium_Webdriver_Test_01.java

public static void main(String[] args) {
    // Creates a new instance of the Firefox driver
    WebDriver driver = new FirefoxDriver();

    // WebDriver.get - Opens a URL in Firefox
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this:
    // driver.navigate().to("http://www.google.com");

    // WebDriver.findElement(By.name("name")) - Accesses the text input element by its name.
    WebElement element = driver.findElement(By.name("q"));

    // .sendKeys("text") - Sends text to text input element.
    element.sendKeys("Thurse");

    // .submit() - Submits the form. Form is found automatically from element.
    element.submit();/*w w  w. j  a  v a 2s.c o m*/

    // System.out.println("text" + some.object()) - Prints something on the NetBeans output window
    // WebDriver.getTitle() - Gets the title of a web page.
    System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("thurse");
        }
    });

    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    //Close the browser
    driver.quit();
}

From source file:snapshot.webdriver.WebDriverHelper.java

License:Open Source License

/**
 * Closes the current WebDriver//from   w w  w .  j a  v a2 s  . co  m
 *
 * @param driver
 */
public static void teardownDriver(WebDriver driver) {
    driver.quit();
}

From source file:streaming.crawler.WebDriverResource.java

License:Apache License

private void close() {
    for (WebDriver webDriver : freeDrivers.get(0)) {
        try {//from   w  w w  . j av  a 2s . co  m
            webDriver.quit();
        } catch (Exception e) {

        }
    }
}

From source file:test.chrome.ChromeTest.java

License:Open Source License

public static void chrome(String baseurl, boolean useKeycloak) {

    WebDriver driver = null;
    try {/* w  ww .jav  a  2s . com*/
        DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
        desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        desiredCapabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, false);

        ChromeDriverManager.getInstance().setup();
        driver = new ChromeDriver(desiredCapabilities);
        driver.manage().window().setSize(new Dimension(Utils.WINDOW_WIDTH, Utils.WINDOW_HEIGHT));
        driver.manage().timeouts().implicitlyWait(Utils.DEFAULT_WAITING_TIME, TimeUnit.SECONDS);

        TestScenario.useKeycloak = useKeycloak;
        TestScenario.test(driver, baseurl);
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}