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:WaitTool.java

License:Open Source License

/**
 * Wait for an element to appear on the refreshed web-page.
 * And returns the first WebElement using the given method.
 *
 * This method is to deal with dynamic pages.
 *
 * Some sites I (Mark) have tested have required a page refresh to add additional elements to the DOM.
 * Generally you (Chon) wouldn't need to do this in a typical AJAX scenario.
 *
 * @param WebDriver   The driver object to use to perform this element search
 * @param locator   selector to find the element
 * @param int   The time in seconds to wait until returning a failure
 *
 * @return WebElement   the first WebElement using the given method, or null(if the timeout is reached)
 *
 * @author Mark Collin//from  w w w.j av a  2  s . co m
 */
public static WebElement waitForElementRefresh(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()
        new WebDriverWait(driver, timeOutInSeconds) {
        }.until(new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver driverObject) {
                driverObject.navigate().refresh(); //refresh the page ****************
                return isElementPresentAndDisplay(driverObject, by);
            }
        });
        element = driver.findElement(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return element; //return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java

public static void logout(WebDriver driver1, WebDriverWait wait) throws IOException {
    logger.info("Logout");
    openUserMenu(driver1);/*from   www.j  a  va 2 s. c  om*/
    clickOnLogout(driver1);
    driver1.navigate().refresh();

}

From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java

public static void reloadDashboard(WebDriver driver1, WebDriverWait wait1) throws IOException {
    driver1.navigate().refresh();
    waitUntilWaitForServerDissappears(wait1);
}

From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java

License:Open Source License

/**
 * Wait for an element to appear on the refreshed web-page. And returns the
 * first WebElement using the given method.
 * /*from w w  w .  j a  v  a2  s .  co  m*/
 * This method is to deal with dynamic pages.
 * 
 * Some sites I (Mark) have tested have required a page refresh to add
 * additional elements to the DOM. Generally you (Chon) wouldn't need to do
 * this in a typical AJAX scenario.
 * 
 * @param WebDriver
 *            The driver object to use to perform this element search
 * @param locator
 *            selector to find the element
 * @param int The time in seconds to wait until returning a failure
 * 
 * @return WebElement the first WebElement using the given method, or
 *         null(if the timeout is reached)
 * 
 * @author Mark Collin
 */
public static WebElement waitForElementRefresh(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify
        // implicitlyWait()
        new WebDriverWait(driver, timeOutInSeconds) {
        }.until(new ExpectedCondition<Boolean>() {

            public Boolean apply(WebDriver driverObject) {
                driverObject.navigate().refresh(); // refresh the page
                // ****************
                return isElementPresentAndDisplay(driverObject, by);
            }
        });
        element = driver.findElement(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset
        // implicitlyWait
        return element; // return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:br.com.mundotigre.scripts.WaitTool.java

License:Open Source License

/**
* Wait for an element to appear on the refreshed web-page.
* And returns the first WebElement using the given method.
*
* This method is to deal with dynamic pages.
* 
* Some sites I (Mark) have tested have required a page refresh to add additional elements to the DOM.  
* Generally you (Chon) wouldn't need to do this in a typical AJAX scenario.
* 
* @param WebDriver   The driver object to use to perform this element search
* @param locator   selector to find the element
* @param int   The time in seconds to wait until returning a failure
* 
* @return WebElement   the first WebElement using the given method, or null(if the timeout is reached)
* 
* @author Mark Collin //  w  w  w.  j av a  2 s  .  co  m
*/
public static WebElement waitForElementRefresh(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() 
        new WebDriverWait(driver, timeOutInSeconds) {
        }.until(new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver driverObject) {
                driverObject.navigate().refresh(); //refresh the page ****************
                return isElementPresentAndDisplay(driverObject, by);
            }
        });
        element = driver.findElement(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return element; //return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunnerTest.java

License:Open Source License

@Test
public void testNavigateTo() {
    WebDriver driverExpected = Mockito.mock(WebDriver.class);
    Navigation navigation = Mockito.mock(Navigation.class);
    Mockito.when(driverExpected.navigate()).thenReturn(navigation);
    WebDriverRunner runner = new WebDriverRunner();
    runner.setWebDriver(driverExpected);

    runner.navigateTo("http://www.google.com");

}

From source file:ca.pe.cjsigouin.testinator.selenium.WebDriverMain.java

public static void main(String[] args) {

    System.setProperty("webdriver.gecko.driver", "/home/krystofurr/Programs/selenium/geckodriver");
    System.setProperty("webdriver.chrome.driver", "/home/krystofurr/Programs/selenium/chromedriver");

    //     WebDriver driver = new FirefoxDriver();
    WebDriver driver = new ChromeDriver();
    //     WebDriver driver = new InternetExplorerDriver();

    //Puts an Implicit wait, Will wait for 10 seconds before throwing exception
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //Launch website
    driver.navigate().to(CommonConstants.HOST + CommonConstants.URL_LOGIN);

    driver.findElement(By.id("emailAddress")).sendKeys("cjsigouin@gov.pe.ca");
    driver.findElement(By.id("password")).sendKeys("Test12345!");
    driver.findElement(By.id("loginButton")).click();

    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(//from   w  w w  . j a  v a  2  s .  c om
            ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='serviceWellSection']/div[2]/div/a/b")));

    driver.get(CommonConstants.HOST + CommonConstants.URL_RESERVE_NAME_INTRO);
    WebDriverWait wait2 = new WebDriverWait(driver, 5);

    wait2.until(ExpectedConditions.elementToBeClickable(By.xpath(ReserveNameElement.INTRO_BUTTON_CANCEL)));
    driver.findElement(By.xpath(ReserveNameElement.INTRO_RADIO_RESERVE_NAME)).click();
    //     driver.findElement(By.xpath(ReserveNameElement.INTRO_SELECT_COMPANY_TYPE)).sendKeys("Incorp");

    Select dropdown = new Select(driver.findElement(By.xpath(ReserveNameElement.INTRO_SELECT_COMPANY_TYPE)));
    dropdown.selectByVisibleText("Incorporated");
    driver.findElement(By.xpath(ReserveNameElement.INTRO_BUTTON_NEXT)).click();

    //     WebDriver driver = new FirefoxDriver();
    //     LoginTester login = new LoginTester(driver);
    //     IncorporatedTester tester = new IncorporatedTester(driver);
    //
    //     login.start();

    //     //Maximize the browser
    //     driver.manage().window().maximize();
    //     tester.start();
    //     tester.stop();

    //     // Click on Math Calculators
    //     driver.findElement(By.xpath(".//*[@id='hcalc']/table/tbody/tr/td[2]/div[3]/a")).click();
    //     
    //     // Click on Percent Calculators
    //     driver.findElement(By.xpath(".//*[@id='content']/ul[1]/li[3]/a")).click();
    //     
    //     // Enter value 10 in the first number of the percent Calculator
    //     driver.findElement(By.id("cpar1")).sendKeys(data.getNumberText(2));
    //     
    //     // Enter value 50 in the second number of the percent Calculator
    //     driver.findElement(By.id("cpar2")).sendKeys(data.getNumberText(2));
    //     
    //     // Click Calculate Button
    //     driver.findElement(By.xpath(".//*[@id='content']/table[1]/tbody/tr[2]/td/input[2]")).click();
    //   
    //     
    //     // Get the Result Text based on its xpath
    //     String result = driver.findElement(By.xpath(".//*[@id='content']/p[2]/font/b")).getText();
    //   
    //     
    //     // Print a Log In message to the screen
    //     System.out.println(" The Result is " + result);

    //Close the Browser.
    driver.close();
}

From source file:com.adasasistemas.pilot.webtest3.NewSeleneseIT.java

@Test
public void testSimple() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    FirefoxProfile fp = new FirefoxProfile();

    //   fp.setPreference("browser.startup.homepage", URL);
    // fp.setPreference("startup.homepage_welcome_url", URL);
    //fp.setPreference("startup.homepage_welcome_url.additional", URL);
    FirefoxBinary fb = new FirefoxBinary(new File(NAVIGATOR));
    WebDriver driver = new FirefoxDriver(fb, fp);

    // And now use this to visit NetBeans
    //  driver.get("http://www.netbeans.org");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.netbeans.org");
    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    driver.navigate().to("http://localhost:8085/webtest3");
    //* driver.navigate().refresh();
    //  driver.get("http://localhost:8085/webtest3");
    //    System.out.println(driver.getPageSource());

    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override/*  w w w.j  ava2s  .co  m*/
        public Boolean apply(WebDriver d) {
            System.out.println(d.getPageSource());
            return d.getPageSource().contains("Hello");
        }
    });

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

From source file:com.automationpractice.tests.SaleBanners.java

public static void main(String[] args) {

    //open browser
    System.setProperty("webdriver.chrome.driver", "D:\\selenium test lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://automationpractice.com");

    //test://w  w w. j  ava 2  s  .  c  o  m
    driver.findElement(By.xpath(".//*[@id='htmlcontent_top']/ul/li[1]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_top']/ul/li[2]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[1]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[2]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[3]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[4]/a/img")).click();
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='htmlcontent_home']/ul/li[5]/a/img")).click();

    driver.quit();

}

From source file:com.automationpractice.tests.SortBy.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "D:\\selenium test lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://automationpractice.com");

    //this codes is for automated test "sort product" in page "DRESSES" 
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("price:asc");
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("price:desc");
    driver.navigate().back();/*from   w w w. j  av  a 2 s  . c o m*/
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("name:asc");
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("name:desc");
    driver.quit();
}