Python+selenium Automation Chapter Simulation keyboard operation

Source: Internet
Author: User
Tags delete key

0. Import keyboard class keys ()
    • The keys () class in Selenium provides most of the keyboard manipulation methods, and the Send_keys () method is used to simulate keys on the keyboard.

      # 导入键盘类 Keys()from selenium.webdriver.common.keys import Keys
1. Common keyboard operation:
    • Send_keys (keys.back_space): Delete key (BackSpace)
    • Send_keys (Keys.space): SPACEBAR (space)
    • Send_keys (keys.tab): Tab key (TAB)
    • Send_keys (Keys.escape): Fallback key (ESCAPE)
    • Send_keys (Keys.enter): Enter (enter)
    • Send_keys (Keys.contrl, ' a '): Select All (Ctrl + a)
    • Send_keys (Keys.contrl, ' C '): Copy (Ctrl + D)
    • Send_keys (Keys.contrl, ' x '): Cut (ctrl+x)
    • Send_keys (Keys.contrl, ' V '): Paste (Ctrl + v.)
    • Send_keys (KEYS.F1): Keyboard F1
    • .....
    • Send_keys (KEYS.F12): Keyboard F12
2. Example
from selenium import webdriver  from selenium.webdriver.common.keys import Keys  driver=webdriver.Chrome()  driver.get("http://www.baidu.com")  #输入关键词内容driver.find_element_by_id("kw").send_keys("selenium")  #删除键driver.find_element_by_id("kw").send_keys(Keys.BACK_SPACE)  #空格键 driver.find_element_by_id("kw").send_keys(Keys.SPACE)  #输入内容driver.find_element_by_id("kw").send_keys("教程")  #全选(Ctrl+A)  driver.find_element_by_id("kw").send_keys(Keys.CONTROL,‘a‘) #剪切(Ctrl+X)  driver.find_element_by_id("kw").send_keys(Keys.CONTROL,‘x‘) #粘贴(Ctrl+V)  driver.find_element_by_id("kw").send_keys(Keys.CONTROL,‘v‘)  #回车键  driver.find_element_by_id("kw").send_keys(Keys.ENTER)  

Python+selenium Automation Chapter Simulation keyboard operation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.