-2

I want to open a completely new window in selenium. NOT a new tab, I need to completely close the chrome window and open a new one.

My code is kinda private and I don't want to share it (unless absolutely necessary) but I don't think it's required.

I am using chrome and using selenium in python.

Any help is appreciated

Manny
  • 1
  • 2
  • I'm not sure if this is even possible, please tell me if it is impossible – Manny Mar 09 '22 at 17:48
  • 1
    Does this answer your question? [How to open a new window on a browser using Selenium WebDriver for python?](https://stackoverflow.com/questions/17325629/how-to-open-a-new-window-on-a-browser-using-selenium-webdriver-for-python) – JaSON Mar 09 '22 at 17:52

3 Answers3

0

In order to open a new window with selenium, not a new tab, as you mentioned, you can define a new driver object, something like

driver1 = webdriver.Chrome(executable_path='chromedriver.exe')

And use it additionally to the previously created driver instance.

Prophet
  • 32,350
  • 22
  • 54
  • 79
0

Once you completely close the existing chrome window the existing Web Browsing Session completely gets destroyed.

So to open a new chrome window you have to initialize a new ChromeDriver and a new Browsing Context i.e. combo using the following code block:

compatible code block

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

options = Options()
options.add_argument("start-maximized")
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get('https://www.google.com/')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

A new window would be a new webdriver. However you opened the first window, just do it again.

But the two webdriver references share nothing between them, they are totally independent.

I assume your hangup is that you want to keep state from your previous webdriver in the new one, if that's the case, you will need to implement some sort of userData in the old one so that when you open the new one, you can transfer over your custom stuff before blowing away the old webdriver.