简体   繁体   中英

selenium webdriver sendkeys() using python and firefox

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?

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')

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM