ActionChains的实现

在 WebDriver 中关于鼠标操作的方法由 ActionChains 类提供。ActionChains 类提供的鼠标操作的常用方法:

click()
click_and_hold()
context_click()
double_click()
drag_and_drop()
drag_and_drop_by_offset()
key_down()
key_up()
move_by_offset()
move_to_element()
move_to_element_with_offset()
pause()
perform()
release()
reset_actions()
send_keys()

send_keys_to_element()

示例:

# -*- coding: utf-8 -*-
from selenium import  webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get('http://www.baidu.com')


# 鼠标悬停
setting = driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(setting).perform()

# 打开搜索设置
#driver.find_element_by_link_text("搜索设置").click()
#driver.find_element_by_class_name  ("setpref").click( )
driver.implicitly_wait(2)

#右击
right_click =driver.find_element_by_class_name  ("setpref")
ActionChains(driver).context_click(right_click).perform()
ActionChains(driver).key_down(Keys.CONTROL).key_down(Keys.SHIFT).send_keys('I').key_up(Keys.CONTROL).key_up(Keys.SHIFT).perform()





你可能感兴趣的:(selenium)