0

I want to open google page with a python code in visual studio editor using the following code :

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

#browser = webdriver.Chrome(ChromeDriverManager().install())
Path = "C:\Program Files (x86)\chromedriver.exe"
browser = webdriver.Chrome(Path)
browser.get('https://www.google.com/')

My problem is the chrome window it opens for 2 or 3 secondes and it close. Did some one face this issue ?

1 Answer 1

1

The default framework of visual studio editor would close the Chrome browser, per say any browser client after the last line of your program gets executed.

Hence, once the line of code:

browser.get('https://www.google.com/')

gets executed, the Chrome browser is CLOSED. This is the expected behavior.


Incase you like to keep the Chrome browser OPEN even after the last line of your program gets executed, you can pass the experimental option detach as true as follows:

compatible code

from selenium.webdriver.chrome.options import Options

options = Options()
options.add_experimental_option("detach", True)
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get('https://www.google.com/')
Sign up to request clarification or add additional context in comments.

1 Comment

Even by adding this option it's not working. the chrome closes after 2 or 3 secondes max.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.