python鼠标事件包括哪几种_python+selenium_鼠标事件

引言--在实际的web产品测试中,对于鼠标的操作,不单单只有click(),有时候还要用到右击、双击、拖动等操作,这些操作包含在ActionChains类中。

一、ActionChains类中鼠标操作常用方法:

context_click() :右击

double_click() :双击

drag_and_drop() :拖动

move_to_element() :鼠标移动到一个元素上

举例:

#cording=gbk

import os

from selenium import webdriver

from selenium.webdriver.common.by import By #导入by方法

from selenium.webdriver.common.action_chains import ActionChains ##对鼠标事件操作

current_path=os.path.dirname(__file__)

firefox_path=current_path+"/../webdriver/geckodriver.exe"

driver=webdriver.Firefox(executable_path=firefox_path)

driver.get("http://127.0.0.1/zentao/user-login-L3plbnRhby9teS5odG1s.html")

mouse=ActionChains(driver) #创建一个鼠标对象

# element1=driver.find_element(By.XPATH,"//img[@src='/zentao/theme/default/images/main/zt-logo.png']") #Xpath利用属性定位

element1=driver.find_element(By.XPATH,"//img[contains(@src,'images/main/zt-logo.png')]") #xpath使用包含属性方法定位

mouse.context_click(element1).perform() #执行鼠标右击,.perform() 表示执行

element2=driver.find_element(By.XPATH,"//button[@type='button' and @class='btn' ]") #多属性定位

mouse.move_to_element(element2).perform() #移动到这个元素上

#对元素进行截图

driver.find_element(By.XPATH,"//button[@id='submit'][@type='submit']").screenshot('element1.png')

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值