r/selenium • u/Cautious_Boat_999 • 20d 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?
View all comments
Show parent comment
0
u/Cautious_Boat_999 20d ago
It’s just an example to see whether it will actually work. And it doesn’t.