[Python] Google chrome closes immediately after being launched with selenium

Discussão em 'Python' iniciado por Stack, Março 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am on Mac OS X using selenium with python 3.6.3.

    This code runs fine, opens google chrome and chrome stays open.:

    chrome_options = Options()
    chrome_options.binary_location="../Google Chrome"
    chrome_options.add_argument("disable-infobars");
    driver = webdriver.Chrome(chrome_options=chrome_options)

    driver.get("http://www.google.com/")


    But with the code wrapped inside a function, the browser terminates immediately after opening the page:

    def launchBrowser():
    chrome_options = Options()
    chrome_options.binary_location="../Google Chrome"
    chrome_options.add_argument("disable-infobars");
    driver = webdriver.Chrome(chrome_options=chrome_options)

    driver.get("http://www.google.com/")
    launchBrowser()


    I want to use the same code inside a function while keeping the browser open.

    Continue reading...

Compartilhe esta Página