11
votes

I am using selenium 2.25.0, firefox 3 and python 2.6.6. I am trying to run a selenium function which uses sendkeys():

 Webdriver.find_element_by_name( 'j_username' ).clear()
 webdriver.find_element_by_name( 'j_username' ).send_keys( "username" )

This code works running from my machine. However running from another machine the username field gets left empty and continues with the rest of the script(without reporting any errors).

I can see that the field is cleared before sending the username is attempted so I know there is not a problem with finding the button/naming of the button. I've tried putting pauses inbetween clearing the field and sending the username but this also doesn't seem to work.

I need to keep my firefox and selenium versions the same, is there anything else I can look at to solve this problem?

3
I'm guessing that the problem is related to quite old Firefox version and newer Selenium not playing nicely together. Can you try with some more recent Firefox? - Edu
Yep you're right. The reason for the out of date firefox was for upload of large files. I have updated to Firefox 10 and managed to fix my problem with file upload. All seems to be working now. - Sarah92

3 Answers

8
votes

your code looks odd. typically, you locate an element, and then do actions with it... rather than locating it each time.

try something like this:

from selenium import webdriver

driver = webdriver.Firefox()
elem = driver.find_element_by_name('j_username')
elem.clear()
elem.send_keys('username')
2
votes

Use following as a work around I think It may work.

driver = webdriver.Firefox()
elem = driver.find_element_by_name('j_username')
elem.clear()
app = Application.Application()
app.window_(title_re='*.Firefox.*').TypeKeys('username')

Last two lines are in Python(pyWinauto)

2
votes

My problem was identical, and I solved it by going from selenium==2.42.1 down to selenium==2.25.0

After changing my selenium version the test was able to send_keys() and submit the form using send_keys(Key.ENTER)

I am currently running windowless on a remote Debian Squeeze 6.0.8 server with Iceweasel 3.5.16

Mozilla Iceweasel 3.5.16, Copyright (c) 1998 - 2010 mozilla.org

Distributor ID: Debian
Description:    Debian GNU/Linux 6.0.8 (squeeze)
Release:        6.0.8
Codename:       squeeze