Navigation Commands

1. Navigate to() command

Method:

driver.get(“https://www.w3wiki.org/”);

OR

driver.navigate().to(“https://www.w3wiki.org/”);

Output:

Explanation:

  1. This method loads a new web page in the current browser window.
  2. It accepts a string parameter that specifies the URL of the web page to be loaded.
  3. This method is equivalent to the driver.get() method, which also loads a new web page in the current browser window.
  4. However, the driver.get() method waits for the page to load completely before returning control to the script, while the driver.navigate().to() method does not wait for the page to load and returns immediately.

Therefore, the driver.navigate().to() method is faster than the driver.get() method, but it may cause synchronization issues if the script tries to interact with elements that are not yet loaded on the page.

2. back() Command

Method:

driver.navigate().back();

Output:

Explanation:

  1. This method moves back one step in the browser’s history stack.
  2. It does not accept any parameters and does not return anything.
  3. This method is equivalent to clicking on the back button of the browser.
  4. It can be used to return to the previous web page that was visited in the current browser session.

3. forward() Command

Method:

driver.navigate().forward();

Output:

Explanation:

  1. This method moves forward one step in the browser’s history stack.
  2. It does not accept any parameters and does not return anything.
  3. This method is equivalent to clicking on the forward button of the browser.
  4. It can be used to go to the next web page that was visited in the current browser session after using the back() method.

4. refresh() Command

Method:

driver.navigate().refresh();

Output:

Explanation:

  1. This method reloads the current web page in the browser window.
  2. It does not accept any parameters and does not return anything.
  3. This method is equivalent to clicking on the refresh button of the browser or pressing F5 key on the keyboard.
  4. It can be used to refresh the content of the web page or to retry a failed operation.

Selenium WebDriver – Navigation Commands

Selenium WebDriver is quite a popular open-source framework used for automating web browsers. It helps the developers to automate web-based operations and interactions by creating code in Java, Python, C#, and others. When automating tests, Selenium WebDriver offers a set of navigation commands that let you interact with and manage a web browser’s navigation. In this article, we will learn about the navigation commands in detail.

Similar Reads

What are Navigation Commands?

Navigation commands in Selenium WebDriver perform operations that involve navigating through web pages and controlling browser behavior. These commands provide an efficient way to manage a browser’s history and perform actions like going back and forward between pages and refreshing the current page....

Prerequisites

1. Java Development Kit (JDK): Install the JDK to write and execute Java code....

Navigation Commands

1. Navigate to() command...

Implementation

Interaction with GeeksForGeeks Website using Navigation Commands:...

Conclusion

...