首页 > 其他分享 >鼠标操作

鼠标操作

时间:2022-12-26 16:56:58浏览次数:35  
标签:鼠标 ActionChains driver element -- 操作 ele

ActionChains类提供了鼠标操作的常见方法:
perform():执行 ActionChains 类中存储的所有行为。执行鼠标操作
click(element) -- 点击
context_click(element):右击
double_click(element):双击
move_to_element():鼠标悬停
click_and_hold(element) -- 按住左键不松
release() -- 释放按键
drag_and_drop(src, dest) -- 拖拽
pause() -- 暂停
send_keys_to_element(element, value) -- 往元素上输入内容
scroll_to_element() -- 元素滚动到可见区域
使用步骤:
1、实例化ActionChains类
2、调用你想执行的鼠标操作(可以有多个)
3、调用perform() -- 真正执行鼠标操作。
请注意:当你在执行鼠标操作有关的代码时,请不要动你的鼠标。

selenium3.X ActionChains只是给web自动化用的,鼠标操作。
selenium4.X/appium2.X 兼容了app的触屏操作(appium1.X的触屏操作原来是TouchAction类和MultiAction类)。

链式调用
ActionChains(driver).move_to_element(ele).pause(0.3).click(ele).perform()
鼠标操作的方法返回的都是self
 1 import time
 2 from selenium.webdriver.common.action_chains import ActionChains
 3 from selenium import webdriver
 4 from selenium.webdriver.common.by import By
 5 from selenium.webdriver.support.wait import WebDriverWait
 6 from selenium.webdriver.support import expected_conditions as EC
 7 
 8 
 9 driver =webdriver.Chrome()
10 driver.maximize_window()
11 driver.get("https://www.xxxx.com/")
12 
13 wait = WebDriverWait(driver, 10)
14 # 1、实例化ActionChains类
15 ac = ActionChains(driver)
16 
17 # 找到鼠标要悬浮的元素
18 loc = (By.XPATH,'//*[@id="goodsStandardImg-18"]')
19 wait.until(EC.visibility_of_element_located(loc))
20 ele = driver.find_element(*loc)
21 
22 # 2、链式调用,鼠标的操作
23 ac.move_to_element(ele).pause(0.3).click(ele)
24 
25 # 3、调用perform()
26 ac.perform()
27 
28 # 链式调用
29 # ActionChains(driver).move_to_element(ele).pause(0.3).click(ele).perform()
30 
31 time.sleep(5)
32 driver.quit()

 

标签:鼠标,ActionChains,driver,element,--,操作,ele
From: https://www.cnblogs.com/liyongmei/p/17006175.html

相关文章

  • 鼠标事件
    在​​WebDriver​​​中,关于鼠标相关操作的方法都封装在​​ActionChains​​类中。我们来看看​​ActionChains​​类都提供了哪些鼠标操作的方法:MethodDescriptionclick(......
  • .net core-利用PdfSharpCore 操作PDF实例
    前序使用PdfSharpCore请注意使用XGraphics基类,与System.Drawing的Graphics类似,XGraphics提供XColor(颜色)、XPen(画笔)、XBrush(画刷)、XFont(字体)、XPoint(位置)等对象。提......
  • Bulk批量操作
    ElasticSearch-javaAPI-Bulk批量操作脚本批量操作{"delete":{"_index":"person","_id":"2"}}{"create":{"_index":"person","_id":"5"}}{"name":"田七",&q......
  • 内存映射直接操作GPIO
    起因音乐打铃系统希望通过GPIO来显示一些系统状态,本来是件很简单的事情,orangePizero2本来已经移植好了wiringpi库,库的编译也很简单,使用操作都没什么可说的,demo代码......
  • 麒麟操作系统更改默认PIN码
    麒麟操作系统更改默认开机PIN码的操作过程​1、点击左下角的开始菜单,找到终端安全登录2、打开终端安全登录系统以后,点击修改PIN码,输入原PIN码(默认12345678),开机密码为新PIN......
  • el-radio-group之迷惑操作:label和label
    el-radio-group之迷惑操作:label和label今天学习element-ui的el-radio-group的时候发现el-radio-group的默认值设置无效,但是点击其他单选框可以切换成功。element-ui官......
  • Apache Ranger系列九:修改源码支持URI类型为s3的操作
    问题描述:ranger在checkPrivileges(org.apache.ranger.authorization.hive.authorizer.RangerHiveAuthorizer)时,当类型是uri时会校验格式,必须是hdfs:,file:if(hiveObjTyp......
  • 盘点Python 中字符串的常用操作
    摘要:盘点Python中字符串的几个常用操作,对新手极度的友好。本文分享自华为云社区《​​盘点Python中字符串的常用操作,对新手极度友好​​》,作者:TT-千叶。在Python中字......
  • linux文件操作函数
    前言:    我们在这一节将要讨论linux下文件操作的各个函数.文件的创建和读写文件的各个属性目录文件的操作管道文件----------------------......
  • 盘点Python 中字符串的常用操作
    摘要:盘点Python中字符串的几个常用操作,对新手极度的友好。本文分享自华为云社区《盘点Python中字符串的常用操作,对新手极度友好》,作者:TT-千叶。在Python中字符串......