Browser Navigation in selenium
Let us look at the most important navigation commands which are frequently used while testing:
- Navigate GoToUrl Command
- GoToUrl(String arg0) : void – This method Loads a new web page in the current browser window. It accepts a String parameter and returns nothing.
- Command – driver.navigate().to(webpageurl);
- Example – driver.navigate().to("http://www.google.com");
- Forward Command
- forward() : void – This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything
- Command – driver.navigate().forward();
- Example – driver.navigate().forward();
- Back Command
- back() : void – This method does the same operation as clicking on the Back Button of any browser. It neither accepts nor returns anything.
- Command – driver.navigate().back();
- Example – driver.navigate().back();
- Refresh Command
- refresh() : void – This method Refresh the current page. It neither accepts nor returns anything.
- Command – driver.navigate().refresh();
- Example –driver.navigate().refresh();
Example:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace hello_world
{
class Program
{
static void Main(string[] args)
{
//Creates a new instance of chrome browser
IWebDriver chrome = new ChromeDriver();
//Navigates to google.com
chrome.Navigate().GoToUrl("https://www.google.com");
//Navigates to facebook.com
chrome.Navigate().GoToUrl("https://facebook.com");
//Refreshs facebook.com
chrome.Navigate().Refresh();
//Goes back to google.com
chrome.Navigate().Back();
//goes forth to facebook
chrome.Navigate().Forward();
}
}
}
In the next tutorial let us learn to Inspect web elements!
No comments:
Post a Comment