r/selenium • • 10d 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

9 comments sorted by

2

u/FearAnCheoil 10d ago

Why would you want to do this? Selenium can find things in a page in much better ways.

0

u/Cautious_Boat_999 10d ago

It’s just an example to see whether it will actually work. And it doesn’t.

1

u/paul_h 10d ago

People won't be able to help you much because https://en.wikipedia.org/wiki/XY_problem

-1

u/Cautious_Boat_999 9d ago

What part of “not sending keys” is hard to comprehend?

1

u/Comfortable-Duty7143 4d 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 4d 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

0

u/[deleted] 9d ago

[removed] — view removed comment

0

u/Cautious_Boat_999 9d 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.