1. 右击事件
context_click
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
right_click = driver.find_element_by_id("xx")
ActionChains(driver).context_click(right_click).perform()
2. 鼠标悬停
move_to_element()
from selenium.webdriver.common.action_chains import ActionChains
ele = browser.find_element_by_link_text("产品报价")
ActionChains(browser).move_to_element(ele).perform()
#coding=utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains import time browser = webdriver.Chrome() browser.get(‘http://cms.andisk.com/‘) time.sleep(2) browser.maximize_window() time.sleep(1) ele = browser.find_element_by_link_text("产品报价") time.sleep(2) ActionChains(browser).move_to_element(ele).perform() browser.find_element_by_link_text("集成与定制服务").click() time.sleep(2) browser.quit()
3. 鼠标双击
double_click = driver.find_element_by_id("xx")
ActionChains(driver).double_click(double_click).perform()
4. 鼠标拖放
element = driver.find_element_by_id("")
target = driver.find_element_by_id("")
ActionChains(driver).drag_and_drop(element,target).perform()
5.键盘事件
from selenium.webdriver.common.keys import Keys
s.send_keys(keys.BACKSPACE)
s.send_keys(keys.CONTROL,’a’)
s.send_keys(keys.CONTROL,’x’)
s.send_keys(keys.CONTROL,’v’)
s.send_keys(keys.TAB)
s.send_keys(keys.F1)
s. submit() 模拟回车键
#coding=utf-8 from selenium import webdriver import time from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys browser = webdriver.Chrome() browser.get(‘http://www.maiziedu.com/‘) time.sleep(2) browser.maximize_window() s = browser.find_element_by_name("datasearch") time.sleep(1) s.send_keys(‘python‘) s.send_keys(Keys.BACK_SPACE) time.sleep(1) s.send_keys(Keys.CONTROL,‘a‘) time.sleep(1) s.send_keys(Keys.CONTROL,‘x‘) time.sleep(1) s.send_keys(Keys.CONTROL,‘v‘) time.sleep(2) browser.quit()