selenium webdriver sendkeys()使用Python和Firefox [英] selenium webdriver sendkeys() using python and firefox
问题描述
$ p $ Web $
webdriver.find_element_by_name('j_username').send_keys(username)
从我的机器运行的作品。然而,从另一台机器上运行的用户名字段会留空,并继续与脚本的其余部分(不报告任何错误)。
我可以看到该字段被清除之前发送用户名是企图,所以我知道有没有找到按钮/按钮命名的问题。我已经尝试了暂停之间清理领域和发送用户名,但这也似乎没有工作。
我需要保持我的firefox和selenium版本一样,有什么我可以看看解决这个问题吗?
你的代码看起来很奇怪。通常情况下,你找到一个元素,然后做它的行动...而不是每次定位。
尝试这样的:
来自selenium import webdriver
driver = webdriver.Firefox()
elem = driver.find_element_by_name('j_username')
elem.clear()
elem.send_keys('username')
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')
这篇关于selenium webdriver sendkeys()使用Python和Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!