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