r/selenium • • 19d ago

Selenium with Firefox - Python not sending keys

I've been trying like crazy to get a Python program to send keys to the browser. I tried all kinds of stuff and decided to go back to basics, and even the sample code I found doesn't work. I am running this:

# import webdriver
from selenium import webdriver
from time import sleep

# import Action chains
from selenium.webdriver.common.action_chains import ActionChains

# import KEYS
from selenium.webdriver.common.keys import Keys

# create webdriver object
driver = webdriver.Firefox()

# get geeksforgeeks.org
driver.get("https://www.geeksforgeeks.org/")

# create action chain object
action = ActionChains(driver)

# perform the operation
action.key_down(Keys.CONTROL).send_keys('F').key_up(Keys.CONTROL).perform()
sleep(5)

The browser window opens, but the Find dialog never appears. I'm having a similar problem in another piece of code trying to get an ALT-n sequence to fire in the browser.

What's wrong here? I see a lot of posts around the web from people having trouble getting this kind of thing to work with Firefox and Python. Is it just broken?

1 Upvotes

11 comments sorted by

View all comments

Show parent comment

0

u/Cautious_Boat_999 18d ago

Same result. No "find prompt" pops up.

I've done this same test with other "special keys" also. It just doesn't detect them.

I'm going to try with Chrome, as much as I hate to introduce it to my system. This has to be isolated to the firefox webdriver. Can't believe such a basic thing is broken everywhere.