Navigate.To(URL)
This method Load a new web page in the current browser window.
This is done using an HTTP GET operation, and the method will block until the load is complete.
Parameters: URL – It should be a fully qualified URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.qaearth; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.testng.annotations.Test; | |
public class URLExample { | |
@Test | |
public void navigationToURLExample() { | |
FirefoxDriver driver = new FirefoxDriver(); | |
driver.navigate().to("http://www.google.com"); | |
} | |
} |
To move back a single "item" in the web browser's history. And it will not perform any action if you are on the first page viewed.
In the above example, to work with navigate back method, we atleast need to travel to one single page in the browser history.
The first page we have opened is facebook.com page and then traveled to forgot password page. Now the browser has two pages in the history. If we now use navigate.back(), it will redirect the user to facebook.com page.
To move a single "item" forward in the web browser's history. And it will not perform any action if we are on the latest page viewed.
The first page we have opened is facebook.com page and then traveled to forgot password page. Now the browser has two pages in the history. If we now use navigate.back(), it will redirect the user to facebook.com page.
And now again if we navigate.forward(), it will redirect the user to forgot password page.
Navigate.Refresh()
It refreshes the current web page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.qaearth; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.testng.annotations.Test; | |
public class Refresh { | |
@Test | |
public void refresh() throws InterruptedException { | |
FirefoxDriver driver = new FirefoxDriver(); | |
String URL = "http://www.facebook.com"; | |
driver.get(URL); | |
driver.findElement(By.linkText("Forgot your password?")).click(); | |
driver.findElement(By.id("identify_email")).sendKeys("sample@email.com"); | |
driver.navigate().refresh(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.qaearth; | |
import org.openqa.selenium.Keys; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.interactions.Actions; | |
import org.testng.annotations.Test; | |
public class RefreshByKeys { | |
@Test | |
public void refresh() throws InterruptedException { | |
FirefoxDriver driver = new FirefoxDriver(); | |
driver.navigate().to("http://google.com"); | |
Actions actions = new Actions(driver); | |
actions.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform(); | |
} | |
} |
In the above example, we are just refreshing the web page after entering the values using sendkeys().