Browser refresh in different ways using selenium web driver:
==============================================
==============================================
1 1. Refresh command: Most commonly used and simple command for refreshing a webpage.
Public class RefreshGetCurrentUrl {
Public static void main(String[] args) throws Interrupted
Exception
{
WebDriver
driver = new FirefoxDriver ();
driver.manage ().window ().maximize
();
driver.manage ().deleteAllCookies
();
driver.manage ().timeouts ().implicitly
Wait (30, TimeUnit.SECONDS);
driver.get ("http://rameshselenium.blogspot.in/");
Thread.
Sleep (2000);
driver. Navigate ().refresh
();
Thread.
Sleep (2000);
driver.
Quit ();
}
}
2.SendKeys command: Second
most commonly used command for refreshing a webpage. As it is using a send keys
method, we must use this on any Text box on a webpage.
public class RefreshSendKeys {
public static void main(String[] args) throws InterruptedException
{
WebDriver
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
driver.get("http://rameshselenium.blogspot.in/");
Thread.sleep(2000);
driver.findElement(By.id("ramesh")).sendKeys(Keys.F5);
Thread.sleep(2000);
driver.quit();
}
}
3. To command: This command is again using the same above concept. navigate(
).to( ) is feeding with a page url and an argument.
public class RefreshGetCurrentUrl {
public static void main(String[] args) throws InterruptedException
{
WebDriver
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
driver.get("http://rameshselenium.blogspot.in/");
Thread.sleep(2000);
driver.navigate().to(driver.getCurrentUrl());
Thread.sleep(2000);
driver.quit();
}
4. Get command: This is a tricky one, as it is using another command as an
argument to it. If you look carefully, it is just feeding get command with a
page url.
public class RefreshGetCurrentUrl {
public static void main(String[] args) throws InterruptedException
{
WebDriver
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
driver.get("http://rameshselenium.blogspot.in/");
Thread.sleep(2000);
driver.get(driver.getCurrentUrl());
Thread.sleep(2000);
driver.quit();
}
}
No comments:
Post a Comment