-2
from selenium import webdriver
from selenium.webdriver import Keys 
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By

s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.get('https://www.google.com')
driver.find_element(By.NAME, 'q').send_keys('Hello world' + Keys.ENTER)`

Help me pls,who faced such problem? There is a solution? The browser starts and after a couple of seconds it closes, although I did not give the command to close. What's wrong?

Prophet
  • 32,350
  • 22
  • 54
  • 79

1 Answers1

0

Try using the detach option when initializing the chromedriver. As following:

from selenium import webdriver
from selenium.webdriver import Keys 
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument("start-maximized")

s = Service(ChromeDriverManager().install())

driver = webdriver.Chrome(options=chrome_options, service=s)

Prophet
  • 32,350
  • 22
  • 54
  • 79