13

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?

2
  • 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? Commented Jan 28, 2013 at 17:17
  • 1
    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. Commented Jan 28, 2013 at 17:27

3 Answers 3

8

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')
Sign up to request clarification or add additional context in comments.

2 Comments

Tried your suggestion, still the same problem with leaving the field blank.
Way described by Corey is right, but you need to import Keys before you can use it. I suggest you to look the docs instead ask anything you can imagine... here: selenium-python.readthedocs.org
2

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)

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.