0

The code works fine in IDLE, but when double-clicking the file or running from the command line the rest of the program doesn't seem to work, as my key handler does not react to key presses. I believe it may have something to do with chromedriver taking over the cmd window, but I am fairly new to python and I am not sure. Attached is the code, and it will open the chromedriver window and not bind the key presses which it would bind in 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)
Matt Vincent
  • 59
  • 1
  • 6

1 Answers1

0

headless/monitor

I don't run headless, but on linux based systems I have to. In IDLE a display will have implicitly been setup

os.environ["DISPLAY"] = ":0.0"
Rob Raymond
  • 29,118
  • 3
  • 14
  • 30
  • For this use of selenium I need to have the visible UI of Chrome, and regardless, this does not solve the issue of the keyboard handler when used – Matt Vincent Jul 09 '20 at 18:41