我试图选择文本框中的所有文本以清除文本框.我使用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))
有帮助吗?
谢谢,
阿米特
解决方法:
我在WebDriver中使用clear()而没有任何麻烦……
el = self.selenium.find_element_by_name(name)
el.clear()