"Selenium2 Python Automation Test" (5)--keyboard events

Source: Internet
Author: User

Keyboard events are some of the actions on the keyboard, such as Ctrl +c,ctrl+v,ctrl+x, and so on.

The operation on the keyboard requires a library to be imported into another keyboard:

from selenium.webdriver.common.keys import Keys

For example, you want to enter the "automated test" in the search box, but now you want to search "automated testing", is to delete a word, we know, is to press the BACKSPACE key on the keyboard can be, this time you need keyboard operation:

driver.find_element_by_xpath("xpath的定位").send_keys(Keys.BACK_SPACE)

That's all you can do.

The next piece of code, you'll remember:

 # coding:utf-8from Selenium import webdriverfrom time import Sleepfrom Selenium.webdriver.common.keys im Port Keysdriver = Webdriver. Firefox () driver.get ("http://www.baidu.com") # Enter the contents of the Input box driver.find_element_by_id ("kw"). Send_keys ("Selenium") sleep ( 3) # Delete a mdriver.find_element_by_id ("kw") with multiple inputs. Send_keys (Keys.back_space) Sleep (3) # Continue typing tutorial driver.find_element_by_ ID ("kw"). Send_keys (U "tutorial") Sleep (3) # CTRL + A Select all input box content driver.find_element_by_id ("kw"). Send_keys (Keys.control, ' a ') Sleep (3) # ctrl+x cut input Box contents driver.find_element_by_id ("kw"). Send_keys (Keys.control, ' X ') sleep (3) # input box re-enter content, Search driver.find_element_by_id ("kw"). Send_keys (Keys.control, ' V ') Sleep (3) # Use the Enter keyboard instead of the Click action driver.find_element_by_id (" Su "). Send_keys (Keys.enter) sleep (3) driver.quit () 
?

Understand the above content is almost, if the new needs only need Baidu, to know that we can not put all things in mind, as long as the introduction, know how Baidu, that the purpose is reached, of course, if you can remember, then you are more powerful, anyway, I can't remember.

Public search " Automated test practice" or scan the QR code below to add attention ~ ~ ~

"Selenium2 Python Automation Test" (5)--keyboard events

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.