Google chrome closes immediately after being launched with selenium

后端 未结 8 1103
说谎
说谎 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:08

    This is somewhat old, but the answers on here didn't solve the issue. A little googling got me here

    http://chromedriver.chromium.org/getting-started

    The test code here uses sleep to keep the browser open. I'm not sure if there are better options, so I will update this as I learn.

    import time
    from selenium import webdriver
    
        driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.
        driver.get('http://www.google.com/xhtml');
        time.sleep(5) # Let the user actually see something!
        search_box = driver.find_element_by_name('q')
        search_box.send_keys('ChromeDriver')
        search_box.submit()
        time.sleep(5) # Let the user actually see something!
        driver.quit() 
    

提交回复
热议问题