美文网首页
selenium-模拟键盘事件(回车、删除、刷新等)

selenium-模拟键盘事件(回车、删除、刷新等)

作者: 忘了呼吸的那只猫 | 来源:发表于2020-09-01 13:37 被阅读0次

    sendkeys可以模拟键盘输入,也可以用来模拟键盘上的按键,甚至是组合键

    键值 解释
    send_keys(Keys.BACK_SPACE) 删除键BackSpace
    send_keys(Keys.SPACE) 空格键Space
    send_keys(Keys.TAB) 制表键Tab
    send_keys(Keys.ESPACE) 回退键Esc
    send_keys(Keys.ENTER) 回车键Enter
    send_keys(Keys.CONTROL,‘a’) 全选Ctrl+A
    send_keys(Keys.CONTROL,‘c’) 复制CTRL+C
    send_keys(Keys.CONTROL,‘x’) 剪切CTRL+X
    send_keys(Keys.CONTROL,‘v’) 粘贴Ctrl+V
    send_keys(Keys.F1) 键盘F1
    send_keys(Keys.F12) 键盘F12
    from selenium import webdriver
    from [selenium.webdriver.common.by](http://selenium.webdriver.common.by/) import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.action_chains import ActionChains
    from time import sleep,ctime
    driver = webdriver.Firefox()
    driver.get(“[https://www.baidu.com](https://www.baidu.com/)”)
    el = driver.find_element([By.ID](http://by.id/), “kw”)
    el.send_keys(“seleniumm”)
    el.send_keys(Keys.BACK_SPACE)
    el.send_keys(Keys.SPACE)
    el.send_keys(“教程”)
    el.send_keys(Keys.CONTROL, ‘a’)
    el.send_keys(Keys.CONTROL, ‘x’)
    el.send_keys(Keys.CONTROL, ‘v’)
    el.send_keys(Keys.ENTER)
    driver.close()
    

    相关文章

      网友评论

          本文标题:selenium-模拟键盘事件(回车、删除、刷新等)

          本文链接:https://www.haomeiwen.com/subject/vtvhsktx.html