鼠标事件

鼠标事件除了左键点击(click),还有其它的操作,这里介绍几种常用的鼠标事件:

1.鼠标右击

2.鼠标双击

3.鼠标悬停

4.鼠标拖动

在WebDriver 中这些关于鼠标操作的方法由ActionChains 类提供鼠标事件需要先导入模块:

from selenium.webdriver.common.action_chains importActionChains

鼠标右击:context_click()

Selenium2+Python2.0自动化测试【5】 鼠标事件

鼠标双击:double_click()

Selenium2+Python2.0自动化测试【5】 鼠标事件

鼠标悬停:move_to_element()

 Selenium2+Python2.0自动化测试【5】 鼠标事件

鼠标拖动:drag_and_drop(source, target)   

—source:鼠标按下的源元素;target:鼠标释放的目标元素

—如:element = driver.find_element_by_name("name")

         target = driver.find_element_by_name("name")

        ActionChains(driver).drag_and_drop(element, target).perform()


相关文章: