driver.Navigate().GoToUrl("/") sets the location to "/" instead of "http://www.domain.com/"
another example would be
driver.Navigate().GoToUrl("/view1") sets the location to "/view1" instead of "http://www.domain.com/view1"
Either example would cause the browser to return with address isn't valid.
you can use a Java URI to calculate a path relative to the current uri or domain:
import java.net.URI;
driver.get("http://example.org/one/");
// http://example.org/one/two/
driver.get(new URI(driver.getCurrentUrl()).resolve("two/").toString());
// http://example.org/one/two/three/?x=1
driver.get(new URI(driver.getCurrentUrl()).resolve("three/?x=1").toString());
// http://example.org/one/two/three/four/?y=2
driver.get(new URI(driver.getCurrentUrl()).resolve("./four/?y=2").toString());
// http://example.org/one/two/three/five/
driver.get(new URI(driver.getCurrentUrl()).resolve("../five/").toString());
// http://example.org/six
driver.get(new URI(driver.getCurrentUrl()).resolve("/six").toString());
If you're able to calculate the url without using getCurrentUrl(), it might make your code more readable.
The solution now is to use:
driver.Navigate().GoToRelativePath("/view1");
and you will be navigated within the same domain.
UPDATE: This was valid in Selenium WebDriver 2.42 but does not seem to be listed in 3.1 the solution would be
driver.Navigate().GoToUrl(baseUrl + "/view1")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With