Selenium Learning: Keyboard events

Source: Internet
Author: User

The Keys class provides all the key methods on the keyboard. Send_keys method used to simulate keyboard input

The following code:

From time import *from Selenium import webdriver# introduction of the keys module from selenium.webdriver.common.keys import keysdriver = webdrive R.chrome () url = "https://www.baidu.com" Print (' new access%s '% (URL)) driver.get (URL) #输入框输入内容driver. find_element_by_ ID (' kw '). Send_keys (' Seleniumm ') #删除多输入的一个mdriver. find_element_by_id (' kw '). Send_keys (keys.back_space) #输入空格 + ' Tutorials ' driver.find_element_by_id (' kw '). Send_keys (Keys.space) driver.find_element_by_id (' kw '). Send_keys (' tutorial ') sleep (3 ) #全选输入框driver. find_element_by_id (' kw '). Send_keys (Keys.control, ' a ') #剪切输入框sleep (3) driver.find_element_by_id (' kw ') ). Send_keys (Keys.control, ' x ') #粘贴输入框sleep (3) driver.find_element_by_id (' kw '). Send_keys (Keys.control, ' V ') # Enter instead of Clicksleep (3) driver.find_element_by_id (' kw '). Send_keys (Keys.enter) sleep () Driver.quit ()

Common keyboard Operations:

Send_keys (keys.back_space) Delete key (BackSpace)

Send_keys (keys.space) space key

Send_keys (keys_tab) Tab key

Send_keys (keys_escape) fallback key

Send_keys (keys_enter) Enter

Send_keys (keys.contral, ' a ') Select All (Ctrl + a)

Send_keys (keys.contral, ' C ') copy (Ctrl + D)

Send_keys (keys.contral, ' X ') cut (ctrl+x)

Send_keys (keys.contral, ' V ') paste (Ctrl + v.)

Send_keys (KEYS.F1) keyboard F1

....

Send_keys (KEYS.F12) keyboard F12

Selenium Learning: Keyboard events

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.