Selenium-webdriver-keys Class (keyboard operation)

Source: Internet
Author: User

The keys () class provides methods for almost all keys on the keyboard, which can be used to simulate keys on a keyboard, including various key combinations, such as CTRL + A, Ctrl+x,ctrl+c, Ctrl + V, and so on.

From selenium import WebdriverFrom Selenium.webdriver.common.keys import keysFrom time Import sleepdriver = Webdriver. Chrome () driver.get ("http://www.baidu.com") # input box enter the content driver.find_element_by_id ("kw").Send_keys("Seleniumm") Sleep (10) # Delete a mdriver.find_element_by_id ("kw") with multiple inputs. Send_keys (Keys.back_spaceSleep (10) # Enter the SPACEBAR + "tutorial" driver.find_element_by_id ("kw"). Send_keys (Keys.space) driver.find_element_by_id ("kw"). Send_keys ("tutorial") Sleep # Ctrl + A Select all input box contents driver.find_element_by_id ("kw"). Send_ KeysKeys.control, ' a') Sleep # ctrl+x cut the input box contents driver.find_element_by_id ("kw"). Send_keys (Keys.control, ' x ') Sleep # Ctrl + V paste the contents into the input box driver.find_element_by_id ("kw"). Send_keys (Keys.control, ' V 'Sleep (10) # driver.find_element_by_id ("su") using the ENTER key instead of the click operation. Send_keys (Keys.enter) Sleep (driver.quit) ()

  

In addition, there are simulations of other keys:

    • Send_keys (Keys.tab) Tab key (tab)

    • Send_keys (Keys.escape) fallback key (ESC)

    • Send_keys (KEYS.F1) keyboard F1

    • ......

    • Send_keys (KEYS.F12) keyboard F12

Reference: http://www.testclass.net/selenium_python/keyword-event/

Selenium-webdriver-keys Class (keyboard operation)

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.