0

I need to open two browser windows at the same time.

For example, when browsing a page in a window and if I click on the link present in that window, that link (URL) should open in a new browser window, not in a new tab.

I tried with multiple driver options and it was calling driver.exe two times and also I've used Ctrl + N key. But it is opening the new browser window without the URL.

When I click on the link in a page, I need that link to open in a new browser window, not in the new tab.

Please help me how to implement this.

2
  • Why you need selenium with two windows? Selenium is for browser automation. If the app you are automating opens new tab or window, switch to it. If not, you don't have the problem. May 17, 2017 at 13:55
  • Why can't you just grab the link and, if necessary, cookies, of your first session and put them into the second window?
    – Daniel
    Aug 18, 2017 at 15:23

2 Answers 2

2

Suggestion

If new window is must, then you can use this workaround.
1. Fetch the link driver.find_element_by_xpath(xpath).get_attribute("href") and save it in a variable.
   Eg: link = driver.find_element_by_xpath(xpath).get_attribute("href")
2. Launch a new web browser using driver1 = webdriver.Chrome() and navigate to the saved url.
   Eg: driver1 = webdriver.Chrome
         driver1.get("http://webserver.com/baseuri"+link)

Now you can use both driver and driver1 objects

0

If a new window is a must, I suggest you explore the following options.

Alternative: inject code into your HTML that will force a new window to open - or use a plugin. Both options have code examples listed in this StackOverflow question.

Alternative: set the browser options to always open links in a new window. I think for IE it uses what you've set it to in the browser options themselves. For other browsers, you might want to use the Selenium class to set options for the driver instance - if those even exist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.