navigate() method in selenium is very frequently used method. Using selenium navigate to url method, driver can navigate back, forward, refresh browser and navigate to specific URL. navigate() is very simple method and we can use it verify quickly in our selenium webdriver tests. Lets see how we can use navigate() method in selenium webdriver.
Navigation command in selenium
When you want to navigate specific URL in between your test then you can use Selenium navigate to url. Syntax for navigate to url in selenium is driver.navigate().to("Your URL");.
Other usages of navigate method in selenium
Also you can navigate back in selenium. Syntax for selenium go back to previous page is driver.navigate().back();. selenium navigate back to previous page using this syntax. Also you can navigate forward in selenium using driver.navigate().forward(); syntax.
Selenium refresh page
You can refresh page in selenium using navigate method as well. selenium webdriver refresh page can be done using driver.navigate().refresh();. It will refresh page in selenium test.
How to use navigate() to url in selenium?
package TestPack;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class testnavigate {
public static void main(String[] args) {
String exePath = "D:\\chromedriver_win32\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
//Navigate to Given URL in selenium
driver.navigate().to("http://only-testing-blog.blogspot.com/2014/01/new-testing.html");
//Click on Link on page to redirect on other URL
driver.findElement(By.xpath("//a[contains(text(),'Click Here')]")).click();
//Navigate back to previous URL. Same as click Back button in browser.
driver.navigate().back();
//Navigate forward to Next URL. Same as click Forward button in browser.
driver.navigate().forward();
//Refresh page. Same as F5 in browser using selenium navigate
driver.navigate().refresh();
}
}
Do you know how to use switchTo() with iFrames?
When to use selenium navigate() method?
You can use navigate() method to navigate on given URL, Go Back, Go Forward browser button actions, and refresh browser tab.
No comments:
Post a Comment