Driver.navigate.refresh command Send Keys command Driver.navigate.to command
Driver.navigate.refresh command:
This is the inbuilt method for performing page refresh operation provided by Selenium web driver. This command is the most commonly used command across test automation for performing a page refresh operation. Refresh command can be used in a simple way as mentioned below. Navigation is an interface that is used to perform various browser operations like navigating to the previous page, navigating to next page, page refresh, browser close. Navigation interface methods can be accessed using the command driver.navigate(). Refresh method of Navigation interface does not take any arguments or return any values.
Example:
Test Scenario:
Open firefox browser with web page – http://demo.guru99.com/selenium/guru99home/ Once the page is loaded successfully, refresh the web page using driver.navigate.refresh method Close the browser using driver.close() method
Code
Code Output: Initial page load
After page refresh operation… the video has changed
Multiple other ways to refresh a page
1) Get method:
Get method can be used in a recursive way to refresh a page. In order to achieve this, we need to pass another method as an argument to the get method.
Example:
2) Navigate method:
This method uses the same concept of recursion as mentioned above. getCurrentURL() method is passed as an argument to driver.navigate.to method.
Example:
3) Send Keys method using F5 Key:
This is the second most commonly used method to refresh a page in Selenium. It takes the refresh key (F5 Key) as an argument to send keys method. Since send keys works only on web elements rather than the browser, we must initially identify a valid web element on the web page and then use the send keys method. This can be accomplished as shown below.
Example:
4) Send Keys method using ASCII Code:
This method uses the same concept as above, but instead of passing the F5 key as an argument, we send the ASCII Code of refresh key as an argument. This can be accomplished as shown below.
Summary:
Page refresh operation ensures that all the web elements of a page are loaded completely before we proceed with our test cases automation Most commonly used method for page refresh in Selenium is the driver.navigate().refresh() method Get method and navigate methods include the recursive ways to refresh a page in Selenium Send Keys method can be used to refresh a page either by passing F5 key as an argument or its corresponding ASCII Code