1 mouse integration in Webdriver. Actionchains. Click, double click, right-click, drag-and-drop, and so on.
2 Keyboard Introduction package from Selenium.webdriver.common.keys import keys. There are almost always buttons on the keyboard.
#Coding=utf-8#Mouse webdriver. Actionchains#Keyboard keys fromSeleniumImportWebdriver fromSelenium.webdriver.common.keysImportKeysImporttimekeys.dr=Webdriver. Firefox (). Dr.get ("https://www.baidu.com") dr.implicitly_wait (10) Moreproduct= Dr.find_element_by_css_selector ("A.bri") Webdriver. Actionchains (DR) Move_to_element (Moreproduct). Perform () Time.sleep (3) kw= dr.find_element_by_id ("kw")#Webdriver. Actionchains (DR) Context_click (kw). Perform () #鼠标右击Kw.send_keys ('Test')#Keyboard InputTime.sleep (2)#Kw.send_keys (Keys.control, ' a ') #组合键ctrl +aKw.send_keys (keys.back_space) time.sleep (2) Kw.send_keys (Keys.return) time.sleep (2) Dr.quit ()
Selenium Getting Started 12 mouse operation, keyboard input