【问题标题】:To send threekeys using send_keys() in selenium python webdriver在 selenium python webdriver 中使用 send_keys() 发送三键
【发布时间】:2017-08-16 23:26:36
【问题描述】:

我正在尝试在默认值为 0.00 的文本框中键入一个浮点数。但它试图附加而不是覆盖它。我尝试使用 .clear() 然后 send_keys('123.00') 但它仍然被附加. 然后我尝试使用 send_keys(Keys.CONTROL+'a','123.00')。它只更新 0.00。

非常感谢任何帮助。

更多信息.. 网址:http://new.ossmoketest.appspot.com 用户名:senthil.arumugam@mycompanyname.com -- mycompanyname = orangescape(抱歉避免垃圾邮件) 现在不需要密码。 点击购买订单...在表格中请新产品和新价格...自动化示例应用程序..谢谢

【问题讨论】:

  • 在您的问题中添加更多实际代码
  • 最后我找到了答案... send_keys(Keys.CONTROL+'a'+Keys.NULL, str(newprice))

标签: python selenium webdriver


【解决方案1】:

我在以下方面取得了不错的成绩:

from selenium.webdriver.common.keys import Keys

element.send_keys(Keys.CONTROL, 'a')
element.send_keys('123.00')

如果这不起作用,可能与网页中的代码有关。

【讨论】:

  • @Miebster 谢谢!
【解决方案2】:

除非您有自定义编辑框,否则click() 应该适合您:

from selenium.webdriver import Firefox

b = Firefox()
b.get('http://google.com')
e = b.find_element_by_id('lst-ib')

e.click()  # is optional, but makes sure the focus is on editbox.
e.send_keys('12.34')
e.get_attribute('value')
# outputs: u'12.34'

e.click()
e.clear()
e.get_attribute('value')
# outputs: u''

e.send_keys('56.78')
e.get_attribute('value')
# outputs: u'56.78'

【讨论】:

    【解决方案3】:

    我刚刚找到了 clear() 命令 - 请参阅 here:

    如果此元素是文本输入元素,则会清除该值。对其他元素没有影响。文本输入元素是 INPUT 和 TEXTAREA 元素。

    编辑: 所以你的方法是:

       element.clear();
       element.sendKeys('123.00');
    

    【讨论】:

      【解决方案4】:

      我遇到了其他答案中给出的所有示例的问题。

      el.send_keys(Keys.CONTROL + 'a' + Keys.NULL, 'your string')
      

      在我参与过的所有项目中都工作过,所以我已经将它包装到我自己的 Webdriver 类实现中,并具有更强大的操作。

      【讨论】:

        猜你喜欢
        • 2020-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-12
        • 1970-01-01
        • 2014-09-24
        • 2020-05-16
        • 2019-11-18
        相关资源
        最近更新 更多