Google chrome closes immediately after being launched with selenium

后端 未结 8 982
说谎
说谎 2021-01-19 09:37

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         


        
相关标签:
8条回答
  • 2021-01-19 10:16

    As per the code block you shared there can be 3 possible solutions as follows :

    • In the binary_location you have to change the .. to . (. denotes Project Workspace)
    • In the binary_location you have to change the .. to /myspace/chrome (Absolute Chrome Binary)
    • While initiating the driver, add the switch executable_path :

      driver = webdriver.Chrome(chrome_options=options, executable_path=r'/your_path/chromedriver')
      
    0 讨论(0)
  • 2021-01-19 10:23

    To make the borwser stay open I am doing this:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    def browser_function():
        driver_path = "path/to/chromedriver"
        chr_options = Options()
        chr_options.add_experimental_option("detach", True)
        chr_driver = webdriver.Chrome(driver_path, options=chr_options)
        chr_driver.get("https://target_website.com")
    
    0 讨论(0)
提交回复
热议问题