Browser Navigation in Selenium


Browser Navigation in selenium


Let us look at the most important navigation commands which are frequently used while testing:

  1. 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");
  2. 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();
  3. 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(); 
  4. 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