Python脚本在启动chromedriver后停止在CMD中执行



代码在IDLE中运行良好,但当双击文件或从命令行运行时,程序的其余部分似乎不起作用,因为我的键处理程序对按键没有反应。我相信这可能与chromedriver接管cmd窗口有关,但我对python相当陌生,我不确定。附件是代码,它将打开chromedriver窗口,而不会绑定在IDLE:中绑定的按键

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import Select
import keyboard
from tkinter import *
from tkinter import messagebox
address = {}
chrome_options = webdriver.ChromeOptions(); 
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
chrome_options.add_argument("--disable-extensions")
chromeDriverPath = 'C:/ChromeDriver/chromedriver.exe'
def keyboardHandler(keyboardEvent):
if keyboardEvent.name == "f7":
copyAddress(driver)
elif keyboardEvent.name == "f9":
paste(driver)
#Script will launch browser when f7 is pressed
keyboard.wait('f7')
driver = webdriver.Chrome(chromeDriverPath, options=chrome_options)
driver.get('http://www.ebay.co.uk/')
keyboard.on_press(keyboardHandler)

无头/监视器

我不会无头运行,但在基于linux的系统上我必须这样做

os.environ["DISPLAY"] = ":0.0"

相关内容

  • 没有找到相关文章

最新更新