该代码在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)
答案 0 :(得分:0)