1. 程式人生 > >【2018.05.09】python3.6 + selenium 定位之 滑鼠事件操作+鍵盤事件操作

【2018.05.09】python3.6 + selenium 定位之 滑鼠事件操作+鍵盤事件操作


 

一、簡單操作

    1.點選(滑鼠左鍵)頁面按鈕:click()

    2.請空輸入框:clear()

    3.輸入字串:send_keys()

    4.submit()一般用於模擬回車鍵


鍵盤F1到F12:send_keys(Keys.F1) 把F1改成對應的快捷鍵

複製Ctrl+C:send_keys(Keys.CONTROL,'c') 

貼上Ctrl+V:send_keys(Keys.CONTROL,'v') 

 全選Ctrl+A:send_keys(Keys.CONTROL,'a') 

剪下Ctrl+X:send_keys(Keys.CONTROL,'x') 

製表鍵Tab:  send_keys(Keys.TAB) 

ActionChains

perform() 執行所有ActionChains中的行為

move_to_element() 滑鼠懸停


右擊滑鼠:context_click()

雙擊滑鼠:double_click()


 #coding = utf-8
'''
滑鼠事件操作:

'''
from selenium import webdriver

from selenium.webdriver.common.action_chains import *  #需要載入項
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.implicitly_wait(2)
mouse = driver.find_element_by_link_text('設定')
ActionChains(driver).move_to_element(mouse).perform()    #懸停
以上...歡迎交流,一起學習,麻花藤群728109091