微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我试图选择文本框中的所有文本以清除文本框.我使用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()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐