How to hide Chromedriver console window?

后端 未结 3 509
时光说笑
时光说笑 2020-12-20 08:13

I have a simple Python script which uses selenium and webdriver to open up Facebook in a Chrome window and log in automatically. When I run it, the Chromedriver console win

3条回答
  •  太阳男子
    2020-12-20 08:43

    I had the same problem, but when I run driver.service.stop() it closes Chrome. I worked around it by importing os and firing off a task kill to the chrome process.

    This is another option: first change script extension from .py to .pyw, then:

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import os
    
    driver = webdriver.Chrome(executable_path='C:/apps/chromedriver.exe', service_args=["--verbose", '--log-path=c:/logs/logs/qc1.log'])
    
    driver.get("https://example.com")
    
    switch = driver.find_element_by_id("signInSbmtBtn")
    password = driver.find_element_by_id("password")
    username = driver.find_element_by_id("userid")
    username.send_keys('user');
    password.send_keys('password');
    switch.click();
    
    os.system("taskkill /im chromedriver.exe")
    

提交回复
热议问题