API Summary in Webdriver--about mouse, keyboard events

Source: Internet
Author: User

Mouse events

Before using the mouse operation to first import the class that holds these methods actionchains, the following practice a in the Baidu home hover set element of the analysis, complete import wording as follows:

#Coding=utf-8 fromSeleniumImportWebdriver fromSelenium.webdriver.common.action_chainsImportActionchainsdriver=Webdriver. Chrome () Driver.get ("http://www.baidu.com")#navigate to the element that you want to hover over, the settings element of the Baidu search pageabove = Driver.find_element_by_xpath ("//div[@id = ' u1 ']/a[@name = ' Tj_settingicon ')")#to perform a hover operation on a anchored elementactionchains (Driver). Move_to_element (above). Perform () Driver.quit ()Print the Run complete!"

Other mouse actions are similar to those used above: right-click Actionchains (Driver). Context_click (Element). Perform;

Double-click Actionchains (Driver). Double_click (Element). Perform ();

Drag actionchains (Driver). Drag_and_drop (Element,target). Perform ().

Keyboard events

As with mouse operations, keyboard operations are also placed in a packaged class, which is the Keys. Here's an example of a common keyboard operation:

#Coding=utf-8 fromSeleniumImportWebdriver fromSelenium.webdriver.common.keysImportKeysdriver=Webdriver. Chrome () Driver.get ("http://www.baidu.com")#Input Box input contentDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys ("Seleniumm")#Delete one m of multiple inputsDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys (Keys.back_space)#Enter a space + "tutorial"DRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys (Keys.space) driver.find_element_by_id ("kw"). Send_keys (U"Tutorials")#Select all input box contentsDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys (Keys.control,'A')#cut the contents of the wholeDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys (Keys.control,'X')#copy cut content to the input boxDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys (Keys.control,'V')#Replace the Click operation with the Enter keyDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys (Keys.enter) driver.quit ()Print "Run successfully! "

The above examples cover some basic operations other can think of operations you can query the keys this class to learn oh.


API Summary in Webdriver--about mouse, 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.