鼠标连点测试(连点器速度测试)

鼠标表示鼠标事件。鼠标操作是通过使用低级界面执行的,该界面允许我们向Web浏览器提供虚拟化的设备输入操作。 – 鼠标动作操作方法详细介绍如下: click_and_hold 移动到该元素,然后在给定元素的中间单击(不释放) importtime fromseleniumimportwebdriver fromselenium.webdriver.common.action_chainsimport…

鼠标表明鼠标事情。鼠标实际操作是根据应用低等界面实行的,该界面容许大家向Web电脑浏览器给予虚拟化技术的机器设备键入实际操作。

鼠标姿势操作步骤详解如下所示:

click_and_hold

挪动到该元素,随后在给定元素的正中间点击(不释放出来)

import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


with webdriver.Chrome() as driver:
    driver.get(\'https://www.baidu.com/\')
    time.sleep(2)
    setting = driver.find_element_by_xpath(\'//*[@id=\"s-usersetting-top\" and text()=\"设定\"]\')
    ActionChains(driver).click_and_hold(setting).perform()
    time.sleep(5)

context_click

最先将鼠标挪动到元素的部位,随后在给定元素上实行前后文点击(右键单击)


import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


with webdriver.Chrome() as driver:
    driver.get(\'https://www.runoob.com/python/python-tutorial.html\')
    time.sleep(2)
    setting = driver.find_element_by_xpath(\'//*[@rel=\"noopener noreferrer\" and text()=\"Python 3.X 版本号的实例教程\"]\')
    ActionChains(driver).context_click(setting).perform()
    time.sleep(5)

double_click

挪动到该元素,并在给定元素的正中间双击鼠标


import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


with webdriver.Chrome() as driver:
    driver.get(\'https://www.runoob.com/python/python-tutorial.html\')
    time.sleep(2)
    setting = driver.find_element_by_xpath(\'//*[@rel=\"noopener noreferrer\" and text()=\"Python 3.X 版本号的实例教程\"]\')
    ActionChains(driver).double_click(setting).perform()
    time.sleep(5)

move_to_element

将鼠标移到元素的正中间。实行此使用时,该元素也会翻转到主视图中,再开展精准定位实际操作


import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


with webdriver.Chrome() as driver:
    driver.get(\'https://www.baidu.com/\')
    setting = driver.find_element_by_xpath(\'//*[@id=\"s-usersetting-top\" and @name=\"tj_settingicon\"]\')
    ActionChains(driver).move_to_element(setting).perform()
    driver.find_element_by_xpath(\'//*[text()=\"检索设定\"]\').click()
    time.sleep(5)
    

move_by_offset

将鼠标从其所在位置(或0,0)挪动给定的偏移。假如座标在主视图对话框以外,则鼠标将最后在网页对话框以外


import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


with webdriver.Chrome() as driver:
    driver.get(\'https://www.baidu.com/\')
    setting = driver.find_element_by_xpath(\'//*[@id=\"s-usersetting-top\" and @name=\"tj_settingicon\"]\')
    ActionChains(driver).move_to_element(setting).perform()
    time.sleep(5)
    xOffset = 1
    yOffset = 1
    webdriver.ActionChains(driver).move_by_offset(xOffset, yOffset).perform()
    driver.find_element_by_xpath(\'//*[text()=\"检索设定\"]\').click()
    time.sleep(5)
    

如咱们把xOffset和yOffset的值略微设定大一点,设置数值 100,便会报没有在标准的不正确:Message: move target out of bounds


/Users/lifeng/python-virtualenv/venv/bin/python3 /Users/lifeng/python-projects/test-python/selenium_script.py
Traceback (most recent call last):
  File \"/Users/lifeng/python-virtualenv/venv/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py\", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds
  (Session info: chrome=89.0.4389.82)
  

drag_and_drop

最先在源元素上点击并按着,随后运动到总体目标元素的部位,随后释放出来鼠标


import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


with webdriver.Chrome() as driver:
    driver.get(\'https://www.baidu.com/\')
    setting = driver.find_element_by_xpath(\'//*[@id=\"s-usersetting-top\" and @name=\"tj_settingicon\"]\')
    setting_one = driver.find_element_by_xpath(\'//*[@id=\"s-usersetting-top\" and @name=\"tj_settingicon\"]\')
    ActionChains(driver).drag_and_drop(setting, setting_one).perform()
    driver.find_element_by_xpath(\'//*[text()=\"检索设定\"]\').click()
    time.sleep(5)
    

drag_and_drop时要传2个主要参数,传到第一个是源元素setting后按着,再点一下传到的总体目标元素setting_one后,随后再释放出来掉setting_one

drag_and_drop_by_offset

最先在源元素上点击并按着,挪到给定的偏移,随后释放出来鼠标。可对于短信验证码滑动解锁实际操作


import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import UnexpectedAlertPresentException


with webdriver.Chrome() as driver:
    driver.get(\'https://mail.qq.com/\')
    time.sleep(2)
    form_ = driver.find_element_by_xpath(\'//*[@id=\"login_frame\"]\')   driver.switch_to.frame(form_)
    driver.find_element_by_xpath(\'//*[@id=\"u\"]\').click()
    driver.find_element_by_xpath(\'//*[@id=\"u\"]\').send_keys(\'16688888888\')
    driver.find_element_by_xpath(\'//*[@id=\"p\"]\').click()
    driver.find_element_by_xpath(\'//*[@id=\"p\"]\').send_keys(\'12345678999\')
    driver.find_element_by_xpath(\'//*[@id=\"login_button\"]\').click()
    time.sleep(2)
    code_iframe = driver.find_element_by_xpath(\'//*[@id=\"tcaptcha_iframe\"]\')
    driver.switch_to.frame(code_iframe)
    code_offset = driver.find_element_by_xpath(\'//*[@id=\"tcaptcha_drag_button\"]\')
    ActionChains(driver).drag_and_drop_by_offset(code_offset, 179, 0).perform()
    time.sleep(10)

官方网文本文档中的讲解是可以那样实际操作:


from selenium import webdriver


driver = webdriver.Chrome()
driver.get(\"https://crossbrowsertesting.github.io/drag-and-drop\")
sourceEle = driver.find_element(By.ID, \"draggable\")
targetEle  = driver.find_element(By.ID, \"droppable\")
targetEleXOffset = targetEle.location.get(\"x\")
targetEleYOffset = targetEle.location.get(\"y\")

webdriver.ActionChains(driver).drag_and_drop_by_offset(sourceEle, targetEleXOffset, targetEleYOffset).perform()
  

可是实际操作应用了location.get()的方式,运作后出错了:


/Users/lifeng/python-virtualenv/venv/bin/python3 /Users/lifeng/python-projects/test-python/selenium_script.py
Traceback (most recent call last):
  File \"/Users/lifeng/python-projects/test-python/selenium_script.py\", line 29, in <module>
    xOffset = code_offset.location(170)
TypeError: \'dict\' object is not callable

Process finished with exit code 1

release

将释放出来按住的鼠标左键


import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


with webdriver.Chrome() as driver:
    driver.get(\'https://www.runoob.com/python/python-tutorial.html\')
    text_python = driver.find_element_by_xpath(\'//*[@rel=\"noopener noreferrer\" and text()=\"Python 3.X 版本号的实例教程\"]\')
    target_python = driver.find_element_by_xpath(\'//*[@rel=\"noopener noreferrer\" and text()=\"Python 3.X 版本号的实例教程\"]\')
    webdriver.ActionChains(driver).click_and_hold(text_python).move_to_element(target_python).perform()
    webdriver.ActionChains(driver).release().perform()
    time.sleep(1)
    

以上汇总也许能幫助到你,也许协助不了你,但還是期待能幫助到你

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

(14)
上一篇 2022年5月7日 上午11:14
下一篇 2022年5月7日 上午11:18

相关推荐

  • 刷关键词排名推荐,分享seo优化快速排名技巧

    网站的排名有变化是非常正常的,但若是突然下降非常厉害,可能就有问题了,为什么关键词排名下降?如果关键词排名下降怎么办?怎么提高关键词排名呢?对于大家的这些问题,小编这就为大家介绍下关于关键词排名下降的原因,以及如何提高关键词排名。 一、关键词排名下降原因 1.网站优化不当、不稳定 网站自身的原因导致关键词不稳定也是致命的杀手,因为前面我说的那些你做的再好,可能就断送在你网站自身上,网站的自身代码有…

    2022年9月21日
    1840
  • pc微信聊天记录迁移到手机的方法!

    微信已经成为人们日常生活中不可或缺的一款APP,聊天通讯、文件传输都十分依赖它。随着科技迅速发展,手机更新换代的频率也越来越快,这导致人们换手机也变得十分频繁。有些人换手机时就头疼了:旧手机的重要资料如何转移到新手机呢?不慌,今天小助手为粉粉们整理了两种迁移/备份的方法。 方法一:利用微信自带的迁移/备份功能 打开微信,点击【我】>【设置】>【聊天】>【聊天记录备份与迁移】,根据…

    2022年8月17日
    650
  • 股票模拟交易软件下载(初学者模拟炒股软件)

    模拟炒股软件有哪些?哪些比较好? ​​投资有风险,入市需谨慎。2020年,回顾上半年的股市的行情,有人欢喜有人忧,再加上疫情这只黑天鹅,大多数人在股市终究赔多赢少,其中的辛酸滋味也只有自己能够体会。的确多数人都是很难在股市中盈利的,我们需要不断的丰富经验,才能尽可能的发现牛股、选股失利时及时止损,喜欢炒股的话建议还是大家多用模拟软件辅助练习,提升盘感。老话说的好,熟能生巧,当我们不断地总结炒股经验…

    2022年5月4日
    860
  • 新闻通稿格式怎样写啊,分享新闻稿范文大全

    新闻稿的格式: 1.主标题:要夺人眼球,精简干练,使读者一看就能抓住他的内心。 2.副标题:要开门见山,主要写XXX时间,XXX地点举办了什么活动。 3.正文:一般的新闻稿分为三段,以总分总的形式, 第一段为总起句,描述在XXX时间,XXX地点,XXX人物,举办了XXX活动,产生了XXX影响。 第二段为正文,通过详略结合的介绍本次活动的中心内容,内容要精炼短简。 第三段为总结,作为结语要前后呼应,…

    2022年5月26日
    800
  • pdf怎么编辑文字内容,手把手教你如何操作

    如今电子文档的格式有很多种,除了word、ppt这些常用的文档外,pdf也会经常出现个。但是对于pdf文件的编辑操作大多数人都不是太了解。那么pdf文件怎么编辑文字添加图片呢? 使用工具: 查看PDF文件的时候会用到PDF阅读器,但是阅读器只能用来浏览文档,不可以修改编辑文档的内容。对页面内容的修改需要安装对应的编辑工具。 操作步骤: <1>用PDF编辑器打开PDF文件后,选择“编辑内…

    2022年9月1日
    450
  • 客服系统哪个好,智能客服系统排行推荐

    在线客服应用行业逐渐扩大,企业与客户沟通接触的重要平台,企业需求日益增加。 那么怎样选择在线客服系统呢? (一)明确目的 公司在选择在线客服的时候首先要明确目的,工作场景,最终要解决什么问题。例如应用场景是售前咨询和售后处理,那么就更加注重客服质量和服务质量;如果是投诉建议场景,那么就更偏向于问题的解决效率。 (二)价格 价格也是公司会着重考虑的一方面,毕竟可接受价格范围内,性价比越高,公司越能获…

    2022年6月17日
    710
  • excel如何设置条件格式,瞬间提升技能水平的5个操作

    一天,领导让我把销售表格中满足条件的数据突出显示出来。一听到满足条件,很快就想到SUMIF、SUMIFS、COUNTIF、COUNTIFS、IF等与条件相关的函数。 后来实际操作了才知道,这些函数只能对满足条件的数据进行判断、求和和统计等,并不能使用不同的格式来突出显示表格中满足条件的数据或单元格。而且,也不需要使用函数,直接使用Excel提供的条件格式,就能轻松实现。 今天就给大家分享如何使用条…

    2022年9月27日
    1110
  • 毛绒玩具批发市场进货渠道,掌握这个方法就能超低价进货

    在雄安容城县八于乡一个农家院里,一位小伙子正把整捆的PP棉放到机器上“打花”,然后将蓬松的“花絮”充进缝制好的“皮”里;几位农家妇女正忙着手里的活计,有的给小动物装“眼睛”和“鼻子”,有的用针线将充绒的豁口缝上……眨眼的功夫,一个个活泼可爱、栩栩如生的毛绒玩具熊就“下线”了。容城县有这样一个超“萌”的产业,而且等你来当设计师,怎么回事呢?一起来看↓↓↓ 雄安新区党工委副书记、管委会常务副主任刘宝玲…

    2022年9月16日
    620
  • 南京网络推广哪家公司好(南京做推广需要多少钱)

    南京网络广告营销怎么选择?选择哪家公司好?互联网已经成为品牌传播的风口,消费者依赖搜索引擎及网络广告打通咨询购买决策,提升消费选择的精准度,网络广告营销势不可挡,经过南京点畅调研发现,那些网络广告营销做得好的企业已经占据了市场的主导地位。那么怎么去选择网络广告营销公司去打开市场入口? 为什么选择南京点畅信息技术有限公司?点畅从事网络广告营销具备哪些优势? 丰富的广告资源: 首先一家专业的网络广告营…

    2022年10月27日
    470
  • 市场营销专业就业方向,市场营销的就业前景是什么

    2020高考填报志愿时,市场营销专业就业方向有哪些以及就业前景怎么样是广大考生和家长朋友们十分关心的问题,以下是市场营销专业简介、就业方向、就业前景等信息,供大家参考。 市场营销专业是一门科学性和艺术性兼备的应用型学科,是建立在经济科学、行为科学、现代管理理论基础之上的综合性应用科学,研究以满足消费者需求为中心的企业市场营销活动及其规律性,具有全程性、综合性、实践性的特点,是管理类各专业的必修课,…

    2022年7月8日
    780

发表回复

登录后才能评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信