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

1

u/Comfortable-Duty7143 13d ago

are you dealing with an iframe or shadow dom here. sometimes the element looks fine but focus isnt actually landing where send_keys expects. Also interested to hear what geckodriver version you’re on, that combo has bitten me before

1

u/TotGaH 13d ago

send_keys dropping silently is often detection related, the browser gets weird when sites flag automation. geonode rotates proxies so youre not stuck on a burned ip causing those issues, might be worth a shot