zoukankan      html  css  js  c++  java
  • web自动化,selenium 无法清空输入框默认值继续输入

    有的页面输入框自带默认值,想要修改里面的内容时,先使用clear()再send_keys(),这种方式无法清除只会在默认值后面追加内容,不是我想要的结果

    解决方法:

    方法一: 先双击,后直接send_keys(), 不用clear()

    ​ 缺陷: 双击不一定能选中所有内容

    from selenium.webdriver.common.action_chains import ActionChains
    
    element = driver.find_element_by_xpath('xpath路径')
    ActionChains(driver).double_click(element).perform()
    element.send_keys('009')

     

    方法二: 通过键盘操作全选,然后直接send_keys(), 不用clear()

    ​ 完美解决

    from selenium.webdriver.common.keys import Keys
    
    element = driver.find_element_by_xpath('xpath路径')
    element.send_keys(Keys.CONTROL, 'a')
    element.send_keys('009')
  • 相关阅读:
    Chapter 14_2 全局变量声明
    chapter 14_1 环境
    chapter 13_4 跟踪table的访问
    Linq to Entity 和 Linq to Object 异同
    ADO.net实体类操作
    XML
    JavaScript
    CSS样式表
    HTML
    java 反射
  • 原文地址:https://www.cnblogs.com/lulua/p/10882971.html
Copyright © 2011-2022 走看看