Example usage for org.openqa.selenium WebDriver navigate

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

Introduction

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

Prototype

Navigation navigate();

Source Link

Document

An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

Usage

From source file:com.thoughtworks.selenium.webdriven.commands.GoBack.java

License:Apache License

@Override
protected Void handleSeleneseCommand(final WebDriver driver, String ignored, String alsoIgnored) {
    driver.navigate().back();

    return null;//  w  ww .  j av a  2s.c o  m
}

From source file:com.thoughtworks.selenium.webdriven.commands.Refresh.java

License:Apache License

@Override
protected Void handleSeleneseCommand(final WebDriver driver, String ignored, String alsoIgnored) {
    driver.navigate().refresh();

    return null;//  w w  w .ja  va 2  s.co  m
}

From source file:com.vaadin.testbench.TestBenchDriverTest.java

@Test
public void testTestBenchDriverActsAsProxy() {
    FirefoxDriver mockDriver = createMock(FirefoxDriver.class);
    mockDriver.close();//from w w  w. ja v  a2 s.  c o  m
    expectLastCall().once();
    WebElement mockElement = createNiceMock(WebElement.class);
    expect(mockDriver.findElement(isA(By.class))).andReturn(mockElement);
    List<WebElement> elements = Arrays.asList(mockElement);
    expect(mockDriver.findElements(isA(By.class))).andReturn(elements);
    mockDriver.get("foo");
    expectLastCall().once();
    expect(mockDriver.getCurrentUrl()).andReturn("foo");
    expect(mockDriver.getPageSource()).andReturn("<html></html>");
    expect(mockDriver.getTitle()).andReturn("bar");
    expect(mockDriver.getWindowHandle()).andReturn("baz");
    Set<String> handles = new HashSet<String>();
    expect(mockDriver.getWindowHandles()).andReturn(handles);
    Options mockOptions = createNiceMock(Options.class);
    expect(mockDriver.manage()).andReturn(mockOptions);
    Navigation mockNavigation = createNiceMock(Navigation.class);
    expect(mockDriver.navigate()).andReturn(mockNavigation);
    mockDriver.quit();
    expectLastCall().once();
    expect(((JavascriptExecutor) mockDriver).executeScript(anyObject(String.class))).andStubReturn(true);
    TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class);
    expect(mockDriver.switchTo()).andReturn(mockTargetLocator);
    replay(mockDriver);

    // TestBenchDriverProxy driver = new TestBenchDriverProxy(mockDriver);
    WebDriver driver = TestBench.createDriver(mockDriver);
    driver.close();
    By mockBy = createNiceMock(By.class);
    assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands);
    assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands);
    driver.get("foo");
    assertEquals("foo", driver.getCurrentUrl());
    assertEquals("<html></html>", driver.getPageSource());
    assertEquals("bar", driver.getTitle());
    assertEquals("baz", driver.getWindowHandle());
    assertEquals(handles, driver.getWindowHandles());
    assertEquals(mockOptions, driver.manage());
    assertEquals(mockNavigation, driver.navigate());
    driver.quit();
    assertEquals(mockTargetLocator, driver.switchTo());

    verify(mockDriver);
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

License:Apache License

/**
 * Simulates the back button click event of the browser. <br>
 * //w w  w  . j  a  v a 2  s  .com
 * The goBack command waits for the page to load after the navigation
 * 
 * @param waitTime
 *            : Time to wait for goBack command to complete
 * 
 * */
public final void goBack(final String waitTime) {
    WebDriver driver = getDriver();
    try {
        driver.navigate().back();
        super.sleep(Integer.parseInt(waitTime));
        reportresult(true, "GO BACK :", "PASSED", "");
    } catch (Exception e) {
        String errorString = e.getMessage();
        reportresult(true, "GO BACK  :", "FAILED", errorString);
        checkTrue(false, true, "BROWSER BACK :" + "FAILED" + errorString);

    }
}

From source file:com.YOMP.tests.ManageTest.java

License:Open Source License

public static void manageExportRemoveCheckAfterAddingInstances(WebDriver driver) {
    TestUtilities.waitClick(OPEN_MANAGE_DROPDOWN, driver, WAIT_TIME);
    // Navigation and creating autostack to assert export and import button
    // after adding instances.
    TestUtilities.waitClick(NAVIGATE_TO_AUTOSTACK_PAGE, driver, WAIT_TIME);
    Select dropdown = new Select(driver.findElement(By.id("region")));
    dropdown.selectByValue("us-west-2");
    driver.findElement(By.id("name")).sendKeys("test");
    driver.findElement(By.id("tags")).sendKeys("*Jenk*");
    TestUtilities.waitClick(FIND_MEMBERS_BUTTON, driver, WAIT_TIME);
    TestUtilities.waitClick(OK_BUTTON, driver, WAIT_TIME);
    driver.navigate().back();
    ReusableTests.testRemoveButtonVerfication(driver);
    ReusableTests.testExportButtonVerfication(driver);
}

From source file:easycare.cuke.steps.NavigationSteps.java

private <T extends BasePageObject> T iNavigateDirectlyToPatientPage(Class<T> pageClass, String suffix,
        String easycareNumber) {//from   ww  w  . java  2 s.  c  o  m
    final WebDriver driver = currentPage().getDriver();
    String url = currentPage().getBaseUrl() + "/patients/" + easycareNumber + suffix;
    driver.navigate().to(url);
    SeleniumUtils.pollForJqueryToComplete(driver);
    return currentPage(pageClass);
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler26.java

License:Apache License

public void processDriver(WebDriver driver) {

    try {/*from   w w w  . ja  va 2 s  . com*/
        String accumulatedData = "";

        driver.findElement(By.tagName("body")).getAttribute("innerHTML");
        Configuration conf = NutchConfiguration.create();
        new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));

        List<WebElement> atags = driver.findElements(By.tagName("a"));
        int numberofajaxlinks = atags.size();
        for (int i = 0; i < numberofajaxlinks; i++) {

            if (atags.get(i).getAttribute("href") != null
                    && atags.get(i).getAttribute("href").equals("javascript:void(null);")) {

                atags.get(i).click();

                if (i == numberofajaxlinks - 1) {
                    // append everything to the driver in the last round
                    JavascriptExecutor jsx = (JavascriptExecutor) driver;
                    jsx.executeScript(
                            "document.body.innerHTML=document.body.innerHTML " + accumulatedData + ";");
                    continue;
                }

                accumulatedData += driver.findElement(By.tagName("body")).getAttribute("innerHTML");

                // refreshing the handlers as the page was interacted with
                driver.navigate().refresh();
                new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
                atags = driver.findElements(By.tagName("a"));
            }
        }
    } catch (Exception e) {
        LOG.info(StringUtils.stringifyException(e));
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler35.java

License:Apache License

public void processDriver(WebDriver driver) {

    String cur = driver.getCurrentUrl();
    if (cur.contains("/members/") || cur.contains("slickguns.com/alerts/")) {
        Configuration conf = NutchConfiguration.create();
        new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3)); // Wait for the page to load
        try {//w w w . j ava2s  .c  o m
            WebElement uname = driver.findElement(By.cssSelector("input[type=\"text\"]")); // handling multiple text boxes not needed for these pages

            WebElement remember = driver.findElement(By.cssSelector("input[type=\"checkbox\"]"));
            WebElement pwd = driver.findElement(By.cssSelector("input[type=\"password\"]"));
            uname.sendKeys("team35csci572@outlook.com"); // login info for all 403s

            pwd.sendKeys("qwer1234");
            remember.click(); // Check Remember Me option :)

            pwd.submit();
        } catch (Exception e) {
        }
        driver.navigate().refresh();
        //        new WebDriverWait(driver, 5)) // wait for click and any ending client process to compete execution (we are being generous here)

    }
    driver.close();
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.MultiplePatterns.CS572LoginAndClickHandler.java

License:Apache License

private void clickAllAjaxLinks(Configuration conf, WebDriver driver) {
    int count = 0;
    new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
    List<WebElement> atags = driver.findElements(By.tagName("a"));
    int numberofajaxlinks = atags.size();
    for (int i = 0; i < numberofajaxlinks; i++) {

        if ((atags.get(i).getAttribute("href") != null)
                && (atags.get(i).getAttribute("href").contains("javascript:void")
                        || atags.get(i).getAttribute("href").equals("javascript:;")
                        || (atags.get(i).getAttribute("onclick") != null
                                && atags.get(i).getAttribute("onclick").contains("return false")))

        ) {// w  w w.j  a  va  2  s.c  o m

            //         System.out.println(atags.get(i).getAttribute("onClick"));
            try {
                atags.get(i).click();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                count++;
                recordHtmlBodyWithDynamicChange(driver);
            } catch (Exception e) {
                LOG.info(StringUtils.stringifyException(e));
                continue;
            }
        }

        if ((i == numberofajaxlinks - 1) || (count > 18)) { //Don't over-click
            JavascriptExecutor jsx = (JavascriptExecutor) driver;
            Iterator<String> itr = accumulatedDataArrayList.iterator();
            while (itr.hasNext()) {
                String accumulatedData = itr.next();
                try {
                    jsx.executeScript("document.body.innerHTML = document.body.innerHTML + " + "'"
                            + accumulatedData + "'" + ";");
                } catch (Exception ee) {
                    System.out.println(ee);
                }
            }
            accumulatedDataArrayList.clear();
            break;
        }

        if (refreshFlag) {
            refreshFlag = false;
            // refresh page to refresh handler to the un-touched state
            driver.navigate().refresh();
            new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
            atags = driver.findElements(By.tagName("a"));
        }

    }
    //  System.exit(0);

}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.PageNavigation.PageNavigationUK2.java

License:Apache License

public void processDriver(WebDriver driver) {
    try {/*  ww w .j  av a  2  s .c o m*/
        String accumulatedData = driver.findElement(By.tagName("body")).getAttribute("innerHTML");
        Configuration conf = NutchConfiguration.create();
        new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
        //handle ajax content
        List<WebElement> atags = driver.findElements(By.tagName("a"));
        int numberofajaxlinks = atags.size();
        for (int i = 0; i < numberofajaxlinks; i++) {
            if (atags.get(i).getAttribute("href") != null
                    && atags.get(i).getAttribute("href").equals("javascript:void(null);")) {
                atags.get(i).click();
                if (i == numberofajaxlinks - 1) {
                    //append everything to the driver in the last round
                    JavascriptExecutor jsx = (JavascriptExecutor) driver;
                    jsx.executeScript(
                            "document.body.innerHTML=document.body.innerHTML " + accumulatedData + ";");
                    continue;
                }
                accumulatedData += driver.findElement(By.tagName("body")).getAttribute("innerHTML");
                //refreshing the handlers as the page was interacted with
                driver.navigate().refresh();
                new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
                atags = driver.findElements(By.tagName("a"));
            }
        }
        //handle content behind a form
        List<WebElement> inputTags = driver.findElements(By.tagName("input"));
        int numberOfInput = inputTags.size();
        for (int i = 0; i < numberOfInput; i++) {
            if (inputTags.get(i).getAttribute("type") != null
                    && inputTags.get(i).getAttribute("type").equals("text")) {
                //take the first text input as the search input
                inputTags.get(i).sendKeys("weapon");
                inputTags.get(i).submit();
                accumulatedData += driver.findElement(By.tagName("body")).getAttribute("innerHTML");
                JavascriptExecutor jsxInput = (JavascriptExecutor) driver;
                //append the data to the driver
                jsxInput.executeScript(
                        "document.body.innerHTML=document.body.innerHTML " + accumulatedData + ";");
                break;
            }
        }

    } catch (Exception e) {
        LOG.info(StringUtils.stringifyException(e));
    }
}