Selenium
Find Element and FindElements by XPath in Selenium WebDriver
Why do you need Find Element/s command? Interaction with a web page requires a user to locate the web...
During test automation of web-based application, there comes a need for the page to be refreshed multiple times for all web elements to be loaded completely. On the initial page load, some web elements might be loaded while it takes a second page refresh for all web elements to be loaded. This can be done using the refresh command provided by Selenium web driver. Browser refresh operation can be performed using the following ways in Selenium. We will discuss the below mentioned ways in detail throughout the article.
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.
driver.get("http://demo.guru99.com/selenium/guru99home/"); driver.navigate().refresh();
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.
package Guru99Demo; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class RefreshDemo { public static void main(String args[]) throws InterruptedException { System.setProperty("webdriver.chrome.driver", "D: \\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://demo.guru99.com/selenium/guru99home/"); driver.manage().window().maximize(); driver.navigate().refresh(); driver.close(); } }
Code Output:
Initial page load
After page refresh operation… the video has changed
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.
driver.get("https://www.guru99.com"); driver.get(driver.getCurrentURL());
This method uses the same concept of recursion as mentioned above. getCurrentURL() method is passed as an argument to driver.navigate.to method.
driver.get("https://www.guru99.com"); driver.navigate.to(driver.getCurrentURL());
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.
driver.get("https://www.guru99.com"); driver. findElement(By.id("username")).sendKeys(Keys.F5);
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.
driver.get("https://www.guru99.com"); driver. findElement(By.id("username")).sendKeys(“\uE035”);
Why do you need Find Element/s command? Interaction with a web page requires a user to locate the web...
Selenium supports Python and thus can be utilized as Selenium WebDriver with Python for testing....
Project Summary This project will put you in an Online Corporate Test Environment. You will be...
What is an Exceptions? An exception is an error that happens at the time of execution of a...
Accessing Image Links Image links are the links in web pages represented by an image which when...
Installation of Selenium IDE What you need Mozilla Firefox Active Internet Connection If you do...