Navigation Commands
1. Navigate to() command
Method:
driver.get(“https://www.w3wiki.org/”);
OR
driver.navigate().to(“https://www.w3wiki.org/”);
Output:
Explanation:
- This method loads a new web page in the current browser window.
- It accepts a string parameter that specifies the URL of the web page to be loaded.
- This method is equivalent to the driver.get() method, which also loads a new web page in the current browser window.
- 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:
- This method moves back one step in the browser’s history stack.
- It does not accept any parameters and does not return anything.
- This method is equivalent to clicking on the back button of the browser.
- 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:
- This method moves forward one step in the browser’s history stack.
- It does not accept any parameters and does not return anything.
- This method is equivalent to clicking on the forward button of the browser.
- 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:
- This method reloads the current web page in the browser window.
- It does not accept any parameters and does not return anything.
- This method is equivalent to clicking on the refresh button of the browser or pressing F5 key on the keyboard.
- 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.