使用Ctrl + A选择文本框Selenium RC中的所有文本

aba*_*rik 4 python selenium

我试图选择文本框中的所有文本以清除文本框.我使用Ctrl + A在Selenium RC独立2.20.0.jar上使用以下Python 2.7代码执行此操作Windows 7 Firefox上的服务器:

from selenium import selenium
s = selenium('remote-machine-ip', 4444, '*chrome', 'http://my-website-with-textbox')
locator = 'mylocator-of-textbox'
s.open()
s.type(locator, 'mytext')
s.focus(locator)
s.control_key_down()
s.key_down(locator, "A")
s.key_press(locator, "A")
s.key_up(locator, "A")
s.control_key_up()

# Nothing happens here... I cannot see the text getting selected...

# Nothing gets cleared here except the last char
s.key_down(locator, chr(8))  # Pressing backspace
s.key_press(locator, chr(8))
s.key_up(locator, chr(8))
Run Code Online (Sandbox Code Playgroud)

有帮助吗?谢谢,阿米特

sta*_*nka 6

我在WebDriver中使用clear()而没有任何麻烦......

el = self.selenium.find_element_by_name(name)
el.clear()
Run Code Online (Sandbox Code Playgroud)