khanam
khanam

Reputation: 345

How to open a URL in Selenium webdriver other than driver.get() and navigate()?

I'm using Selenium webdriver using Java and i know how to open a browser in 2 ways:

  1. driver.get("some url")
  2. driver.navigate().GoToUrl("some url")

Is there any option available to open a browser other than this?

Upvotes: 1

Views: 33114

Answers (1)

Prateek
Prateek

Reputation: 1145

You can use Java script, there is a command window.location='url' which can help you to achieve this.

String url = "https://www.google.com";
String script = "window.location = \'"+url+"\'";
System.setProperty("webdriver.ie.driver", "Drivers\\IEDriverServer.exe");
WebDriver driver= new FirefoxDriver();
((JavascriptExecutor) driver).executeScript(script);

But again this is NOT a recommended method.

Difference between get() and this command is that, get() would wait for your page to load but NOT Javascript, it would just do what you command and that's it. You would need to separately manage waits then.

So if possible use the traditional methods. :)

Upvotes: 3

Related Questions