本文介绍了如何隐藏geckodriver控制台窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Windows 10上使用python 3.6.7运行Selenium 3.141.0
I'm running Selenium 3.141.0 with python 3.6.7 on windows 10
我的脚本无头运行Firefox驱动程序,但是仍然弹出来自geckodriver的控制台窗口.
My script runs the Firefox driver in headless, however a console window from geckodriver still pops up.
from selenium import webdriver
options = webdriver.FirefoxOptions()
options.add_argument('-headless')
driver = webdriver.Firefox(executable_path=r'c:\webdrivers\geckodriver.exe', log_path='C:\webdrivers\geckodriver.log', firefox_options=options)
driver.get('http://10.0.0.102/')
element = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.ID, "body-home-tile-pgDevServ"))
)
button = driver.find_element_by_id('body-home-tile-pgDevServ')
button.click()
element = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.ID, "devserv-printQ-Inp"))
)
button = driver.find_element_by_id('devserv-printQ-Inp')
button.click()
推荐答案
经过一番混乱之后,似乎添加了 options.add_argument('-disable-gpu')
可以修复它(有时).
After some messing around it seems like adding options.add_argument('--disable-gpu')
fixes it (sometimes).
从vscode运行脚本,使用Windows Task Scheduler运行脚本.从powershell或cmd运行不起作用.
Running the script from vscode works, running the script with windows task scheduler works.Running from powershell or cmd does not work.
这篇关于如何隐藏geckodriver控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!