Example usage for org.openqa.selenium WebDriver get

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

Introduction

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

Prototype

void get(String url);

Source Link

Document

Load a new web page in the current browser window.

Usage

From source file:de.knowwe.uitest.UITestUtils.java

License:Open Source License

/**
 * Loads the given article and waits for it to be loaded. If an alert pops up, it will be accepted.
 *
 * @param url         the url of the running wiki instance
 * @param articleName name of the article to be loaded
 * @param driver      the web driver/*from w w w. ja  v  a  2  s  .  com*/
 */
public static void goToArticle(String url, String articleName, WebDriver driver) {
    driver.get(url + "/Wiki.jsp?page=" + articleName);
    try {
        driver.switchTo().alert().accept();
    } catch (NoAlertPresentException ignore) {
    }
}

From source file:de.knowwe.uitest.UITestUtils.java

License:Open Source License

public static void recompileCurrentArticle(WebDriver driver) {
    String currentUrl = driver.getCurrentUrl();
    if (!currentUrl.contains("&parse=full")) {
        currentUrl += "&parse=full";
    }//from   ww  w. j  a  v  a  2 s.  c o  m
    driver.get(currentUrl);
}

From source file:de.meethub.adapters.eventbrite.EventbriteAdapterServlet.java

License:Open Source License

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    final WebDriver d = new HtmlUnitDriver();
    try {//ww  w.  j  ava  2s. c o m
        d.get(this.baseUrl);
        new WebDriverWait(d, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.className("js-event-list-container")));
        final List<WebElement> eventElements = d.findElements(By.className("event-card__description"));
        final Calendar calendar = this.convertToCalendar(eventElements);
        final CalendarOutputter outputter = new CalendarOutputter();
        response.setContentType("text/calendar;charset=UTF-8");
        outputter.output(calendar, response.getWriter());
    } catch (final ValidationException | ParseException e) {
        throw new ServletException(e);
    } finally {
        d.close();
    }

}

From source file:de.meethub.adapters.hannoverjs.HjsAdapterServlet.java

License:Open Source License

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    final WebDriver d = new HtmlUnitDriver(true);
    try {/*  w ww  . j  a  v  a 2s  .  com*/
        d.get(this.baseUrl);
        final WebElement dateElement = new WebDriverWait(d, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.className("ng-binding")));
        final Calendar calendar = convertToCalendar(dateElement);
        final CalendarOutputter outputter = new CalendarOutputter();
        response.setContentType("text/calendar;charset=UTF-8");
        outputter.output(calendar, response.getWriter());
    } catch (final ValidationException | ParseException e) {
        throw new ServletException(e);
    } finally {
        d.close();
    }

}

From source file:de.meethub.adapters.xing.XingAdapterServlet.java

License:Open Source License

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    final WebDriver d = new HtmlUnitDriver(true);
    try {/*from w ww . j a  v a  2  s.  c o  m*/
        d.get(this.baseUrl);
        new WebDriverWait(d, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.className("event-preview")));
        final Calendar calendar = this.convertToCalendar(d);
        final CalendarOutputter outputter = new CalendarOutputter();
        response.setContentType("text/calendar;charset=UTF-8");
        outputter.output(calendar, response.getWriter());
    } catch (final ValidationException | ParseException e) {
        throw new ServletException(e);
    } finally {
        d.close();
    }
}

From source file:de.tntinteractive.portalsammler.sources.HanVBSourceV1.java

License:Open Source License

@Override
public Pair<Integer, Integer> poll(final SourceSettings settings, final UserInteraction gui,
        final SecureStore store) throws Exception {
    final WebDriver driver = this
            .createDriver("https://www.hannoversche-volksbank.de/ptlweb/WebPortal?bankid=0744");

    final WebElement userField = driver.findElement(By.id("vrkennungalias"));
    userField.sendKeys(settings.get(USER, gui));

    final WebElement passwordField = driver.findElement(By.id("pin"));
    passwordField.sendKeys(settings.get(PASSWORD, gui));

    passwordField.submit();/*from  w  ww .  ja v  a2 s. co  m*/

    waitForPresence(driver, By.linkText("Postkorb"));

    int newDocs = 0;
    int knownDocs = 0;
    try {
        clickLink(driver, "Postkorb");
        waitForPresence(driver, By.name("confirmDeleteMultiMessage"));

        final WebElement form = driver.findElement(By.name("confirmDeleteMultiMessage"));
        final WebElement tbody = form.findElement(By.tagName("tbody"));

        final List<String> links = new ArrayList<String>();
        for (final WebElement tr : tbody.findElements(By.tagName("tr"))) {
            final List<WebElement> tds = tr.findElements(By.tagName("td"));
            final WebElement link = tds.get(2).findElement(By.tagName("a"));
            links.add(link.getAttribute("href"));
        }

        for (final String link : links) {
            driver.get(link);

            final DocumentInfo info = DocumentInfo.create(this.getId(), DocumentFormat.TEXT);
            final StringBuilder content = new StringBuilder();

            driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
            final WebElement fieldset = driver.findElement(By.tagName("fieldset"));
            for (final WebElement div : fieldset.findElements(By.tagName("div"))) {
                if (this.isLabeled(div, "Eingang")) {
                    info.setDate(this.parseTimestamp(div.findElement(By.className("gad-field-box")).getText()));
                } else if (this.isLabeled(div, "Betreff")) {
                    final WebElement data = div.findElement(By.className("gad-field-box"));
                    info.addKeywords(data.findElement(By.tagName("span")).getAttribute("title"));
                } else if (this.isNotLabeled(div)) {
                    content.append(div.getText());
                }
            }
            driver.manage().timeouts().implicitlyWait(WAIT_TIME, TimeUnit.SECONDS);

            if (!store.containsDocument(info)) {
                store.storeDocument(info, content.toString().getBytes("UTF-8"));
                newDocs++;
            } else {
                knownDocs++;
            }
        }

    } finally {
        clickLink(driver, "Logout");
    }
    return Pair.of(newDocs, knownDocs);
}

From source file:de.tudarmstadt.ukp.argumentation.data.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 w w w.  j ava  2 s. c  o  m*/
 */
public String readHTML(String articleUrl) throws InterruptedException {
    // load the url
    WebDriver driver = new FirefoxDriver();
    driver.get(articleUrl);

    // roll-out the entire discussion
    // TODO fix that, is broken in actual versions of Selenium/Firefox
    /*
    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:demo.seleniumtest.Demo.java

public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver",
            "C:\\Users\\Rumyana\\Desktop\\Testing\\SeleniumDrivers\\geckodriver.exe");
    System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\Rumyana\\Desktop\\Testing\\SeleniumDrivers\\chromedriver.exe");

    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    //Reset the Table

    WebDriver driver = new ChromeDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

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

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();//from   w w  w .  j a  v  a 2  s. c o m

    // Check the title of the 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("cheese!");
        }
    });

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

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

From source file:Demo_selenium1.Demo_selenium1.java

/**
 * @param args the command line arguments
 *//*  www.  ja  va  2  s  . com*/
public static void main(String[] args) {
    // TODO code application logic here
    //Here we initialize the firefox webdriver
    WebDriver firefoxDriver = new FirefoxDriver();

    //Open the url which we want in firefox
    firefoxDriver.get("Http://www.google.com");
}

From source file:DerpSelenium.test.java

public static void loginMega(String username, String passwd) throws InterruptedException {
    FirefoxProfile profile = new FirefoxProfile();
    WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("/home/michael/bin/firefox")), profile);
    driver.get("http://www.mega.nz");
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override//from  ww w . jav a2  s .  c o m
        public Boolean apply(WebDriver d) {
            try {
                WebElement loginButton = d.findElement(By.className("top-login-button"));
                System.out.println(loginButton.getText());
            } catch (NoSuchElementException e) {
                return false;
            }

            return true;
        }
    });

    WebElement loginButton = driver.findElement(By.xpath("//a[@class='top-login-button hidden']"));
    loginButton.click();
    WebElement nameElement = driver.findElement(By.name("login-name"));
    WebElement pwElement = driver.findElement(By.name("login-password"));
    nameElement.sendKeys(username);
    pwElement.sendKeys(passwd);
    WebElement submitButton = driver.findElement(By.className("top-dialog-login-button"));
    submitButton.click();

    Thread.sleep(15000);

    String url = driver.getCurrentUrl();
    List<WebElement> elements = driver.findElements(By.tagName("div"));
    Map<String, WebElement> elementMap = new HashMap<>();
    for (Iterator<WebElement> it = elements.iterator(); it.hasNext();) {
        WebElement e = it.next();
        try {
            if (!e.isDisplayed() || !e.isEnabled() || e.getAttribute("class").equals("")) {
                it.remove();
            } else {
                elementMap.put(e.getAttribute("class"), e);
            }
        } catch (StaleElementReferenceException ex) {
            it.remove();
        }

    }

    print("Number of added elements = " + elements.size());

    List<WebElement> contacts = driver
            .findElements(By.xpath("//div[@class='nw-fm-left-icon contacts ui-droppable']"));

    contacts.get(1).click();
    Thread.sleep(2000);
    //driver.navigate().back();
    //Thread.sleep(2000);
    WebElement el = elementMap.get("nw-fm-left-icon shared-with-me ui-droppable");
    if (el == null) {
        print("Element not found");
    } else {
        el.click();
    }

}