Selenium is an open-source framework, therefore please have a glance at the source code here.
GoToUrl() is defined in RemoteNavigator.cs:
/// <summary> /// Navigate to a url for your test /// </summary> /// <param name="url">String of where you want the browser to go to</param> public void GoToUrl(string url) { this.driver.Url = url; } /// <summary> /// Navigate to a url for your test /// </summary> /// <param name="url">Uri object of where you want the browser to go to</param> public void GoToUrl(Uri url) { if (url == null) { throw new ArgumentNullException("url", "URL cannot be null."); } this.driver.Url = url.ToString(); }
So primarily driver.Navigate().GoToUrl(); sets driver.Url internally and I believe there is no difference between the two.
However, the driver.Navigate().GoToUrl() is more flexible, which allows sending either string or Uri as parameter types, while the only string is allowed when setting through a driver.Url.
To your second question, the source code shows that driver.Navigate().Refresh() asks browsers to refresh, while driver.Url tells browsers to navigate. So these two are fundamentally different. For additional details, please see the distinction between Refresh and Navigate function in browser control?
If you want to refresh the page, please use driver.Navigate().Refresh();
Refresh() is defined in RemoteNavigator.cs:
/// <summary>
/// Refresh the browser
/// </summary>
public void Refresh()
{
// driver.SwitchTo().DefaultContent();
this.driver.InternalExecute(DriverCommand.Refresh, null);
}
driver.Url is defined in RemoteWebDriver.cs:
public string Url
{
...
set
{
...
try
{
this.Execute(DriverCommand.Get, parameters);
}
...
}
}
Hope this helps!
If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium automation certification!