mtnpaul
mtnpaul

Reputation: 704

How can you start a browser at a specific URL using the selenium webdriver

So if I do the following:

 driver = webdriver.Chrome() # this results in the browser displaying the about page
 driver.get("http://somesite.com/")  # now the browser goes to the URL

Then if I check the history length via the javascript console in the browser I get a value of 2. I need to simulate the situation where a new tab or window is opened with the URL and thus a history length of 1.

Thanks in advance.

Upvotes: 4

Views: 6757

Answers (3)

WnagoiYy
WnagoiYy

Reputation: 31

options.AddArgument("--homepage \"url\""); like this, set null homepage: options.AddArgument("--homepage \"data:,\"");

Upvotes: 1

eldon111
eldon111

Reputation: 208

You can set some specific flags to pass to your WebDriver when you initialize it. You can see examples here (for Chrome), and there is also a link to a full list of switches. Here is how to set the homepage for ChromeDriver in java:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches",
        Arrays.asList("--homepage=http://somesite.com/"));
WebDriver driver = new ChromeDriver(capabilities);

Upvotes: 6

ddavison
ddavison

Reputation: 29032

I think you have 3 possible options here. (1 may not be)

Option 1:

Design your own get method which will execute javascript. something like, window.location.replace("http://somesite.com/") so it will not be logged into history.

Option 2:

In your validations, just make sure you validate n-1 to "pretend" it wasn't there.

Option 3: (not sure of the possibility of this)

Using the JavascriptExecutor, find out a way that you can modify the history object and just take that initial about:blank history entry out.

Upvotes: 0

Related Questions