selenium鼠标事件

在webdriver中,提供了ActionChains类来封装了鼠标的操作

  • perform()                   #执行所有AtionChains中存储的行为,可以理解为对整个操作的提交动作
  • context_click()        #右击
  • double_click()         #双击
  • drag_and_drop()       #拖动
  • move_to_element()   #鼠标悬停
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
'''
百度首页的“设置”超链接,鼠标悬停的时候会出来多个选项,移动到第二个选项上
'''
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")

#定位到要悬停的元素
element = driver.find_element_by_xpath("//*[@id='u1']/a[8]")
actionchains = ActionChains(driver)
actionchains.move_to_element(element).perform()
element2 = driver.find_element_by_xpath("//*[@id='wrapper']/div[6]/a[2]")
actionchains.move_to_element(element).perform()

你可能感兴趣的:(python_selenium,selenium,鼠标事件)