Navigation

Page navigation kicks in from the start of test execution; it is a fundamental task for each and every use case, especially to browse through the history and navigate backwards and forward. Let's discuss Selenium navigation functions, as follows:

  • The get() function commands the browser to navigate to the URL. In general, the get() function is used to open a web page on every test execution. The onload event lets the browser wait until the complete page is loaded. If the page is overloaded with lots of Ajax calls, there will be delays on page load. The following is the syntax for this function:
    driver.get("URL");
  • The navigate().back() function lets the browser navigate backwards. The following is the syntax for this function:
    driver.navigate().back();

    Here is an alternative method using keyboard actions to navigate web browser history.

    Actions actions = new Actions(driver);
    actions.sendKeys(Keys.BACK_SPACE).perform();
  • The navigate().forward() function allows the browser to navigate forward. This function lets you move a page forward, which is similar to clicking a browser's forward button. The following is the syntax for this function:
    driver.navigate().forward();
  • The navigate().to() function is similar to the get() function in order to access a web page. This function is normally used whenever a user needs to navigate to a specific URL at test. The following is the syntax for this function:
    driver.navigate().to("URL");
  • The refresh() method refreshes the current web page. A page refresh is nothing but reloading a full page. The following is the syntax of this function:
    driver.navigate().refresh();

    There are numerous ways to refresh the current web page. Let's see the methods one by one; however, a few methods are not applicable to Mac:

    Method 1:

    Actions actions = new Actions(driver);
    actions.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform();

    Method 2:

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("history.go(0)");

    Method 3:

    driver.navigate().to(driver.getCurrentUrl());

    Method 4:

    driver.findElement(By.locatorType("path")).sendKeys("uE035");

    Method 5:

    driver.findElement(By.locatorType("path")).sendKeys(Keys.F5);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.197.251