鼠标连点测试(连点器速度测试)
-
-
类目:知识大全
-
联系人:
-
微信号:
-
Q Q 号:
-
手机号:
-
浏览量:
368
【商户信息】
【货源详情】
鼠标表示鼠标事件。 鼠标操作通过低级界面执行,可以为Web浏览器提供虚拟化的设备输入操作。
鼠标的动作操作方法详细介绍如下。
click_and_hold
导航到元素,然后在指定元素的中央单击。 [不解除]
导入时间
来自selenium import web驱动程序
from selenium.web driver.com mon.action _ chainsimportactionchains
with webdriver.Chrome () as driver:
driver.get (' https://www.Baidu.com/' ) ) ) )。
time.sleep(2) )。
setting=driver.find _ element _ by _ XPath (/* [ @ id=' s-user setting-top ' andtext ) )='设置' ] ]
actionchains(driver ).click_and_hold ) setting ).perform ) )。
time.sleep(5) )。
context_click
首先,将鼠标移动到元素的位置,然后在指定元素上执行上下文单击(右键单击)
导入时间
来自selenium import web驱动程序
from selenium.web driver.com mon.action _ chainsimportactionchains
with webdriver.Chrome () as driver:
driver.get (https://www.run OOB.com/python/python-tutorial.html ) )
time.sleep(2) )。
setting=driver.find _ element _ by _ XPath (/* [ @ rel=' noopenernoreferrer ' andtext ) )='Python 3.X版教程'
actionchains(driver ).context_click ) (setting ).perform ) )。
time.sleep(5) )。
double_click
导航到元素,然后双击指定元素的中心
导入时间
来自selenium import web驱动程序
from selenium.web driver.com mon.action _ chainsimportactionchains
with webdriver.Chrome () as driver:
driver.get (https://www.run OOB.com/python/python-tutorial.html ) )
time.sleep(2) )。
setting=driver.find _ element _ by _ XPath (/* [ @ rel=' noopenernoreferrer ' andtext ) )='Python 3.X版教程'
actionchains(driver ).double_click ) (setting ).perform ) )。
time.sleep(5) )。
move_to_element
将鼠标移动到元素的中央。 此操作还会使元素滚动到视图中,并执行放置操作
导入时间
来自selenium import web驱动程序
from selenium.web driver.com mon.action _ chainsimportactionchains
with webdriver.Chrome () as driver:
driver.get (' https://www.Baidu.com/' ) ) ) )。
setting=driver.find _ element _ by _ XPath (/* [ @ id=' s-user setting-top ' and @ name=' TJ _ setting icool
actionchains(driver ).move _ to _ element (setting ).perform ) )
driver.find _ element _ by _ XPath (/* [ text ] )='搜索设置' (click ) ) ) ) ) ) ) )。
time.sleep(5) )。
move_by_offset
将鼠标从当前位置(或0,0 )移动规定的偏移量。 如果坐标位于视图窗口之外,则鼠标最终位于浏览器窗口之外
导入时间
来自selenium import web驱动程序
from selenium.web driver.com mon.action _ chainsimportactionchains
with webdriver.Chrome () as driver:
driver.get (' https://www.Baidu.com/' ) ) ) )。
setting=driver.find _ element _ by _ XPath (/* [ @ id=' s-user setting-top ' and @ name=' TJ _ setting icool
actionchains(driver ).move _ to _ element (setting ).perform ) )
time.sleep(5) )。
xOffset=1
yOffset=1
webdriver.actionchains(driver ).move _ by _ offset (yOffset,yoffset ).perform ) )
driver.find _ element _ by _ XPath (/* [ text ] )='搜索设置' (click ) ) ) ) ) ) ) )。
time.sleep(5) )。
如果将xOffset和yOffset的值设定得稍大,并将设定值设定为100,则会报告超出范围的错误。 消息: movetargetoutofbounds
/users/lifeng/python-virtualenv/venv/bin/python3/users/lifeng/python-projects/test-python/selenium
跟踪后台(mostrecentcalllast ) :
file '/users/lifeng/python-virtualenv/venv/lib/python 3.9/site-packages/selenium/web driver/remote/errrre
raiseexception_class(message,screen,stacktrace ) )。
selenium.com mon.exceptions.movetargetoutofboundsexception : message 3360 movetargetoutofbounds
(session info : chrome=89.0.4389.82 )
drag_and_drop
首先,单击并按住源元素,移动到目标元素的位置,然后释放鼠标按钮
导入时间
来自selenium import web驱动程序
from selenium.web driver.com mon.action _ chainsimportactionchains
with webdriver.Chrome () as driver:
driver.get (' https://www.Baidu.com/' ) ) ) )。
setting=driver.find _ element _ by _ XPath (/* [ @ id=' s-user setting-top ' and @ name=' TJ _ setting icool
setting _ one=driver.find _ element _ by _ XPath ((/) ) id=' s-user setting-top ' and @ name=' TJ _ setttid
actionchains(driver ).drag _ and _ drop (setting,setting_one ).perform ) )
driver.find _ element _ by _ XPath (/* [ text ] )='搜索设置' (click ) ) ) ) ) ) ) )。
time.sleep(5) )。
drag_and_drop需要传递两个参数。 首先要传递的是在源元素setting后按键,然后单击要传递的目标元素setting_one,然后释放setting_one
drag_and_drop_by_offset
首先,单击并按住源元素,移动到指定的偏移,然后释放鼠标按钮。 您可以对验证码滑动解锁操作
导入时间
来自selenium import web驱动程序
from selenium.web driver.com mon.action _ chainsimportactionchains
from selenium.com mon.exceptionsimportunexpectedalertpresentexception
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 ) (16688888 ) )。
driver.find _ element _ by _ XPath (/* [ @ id=' p ' ] ).click ) )
driver.find _ element _ by _ XPath (/* [ @ id=' p ' ] ).send_keys ) (12345678999 ) )
driver.find _ element _ by _ XPath (/* [ @ id=' log in _ button ' ] ).click ) ) )。
time.sleep(2) )。
code _ iframe=driver.find _ element _ by _ XPath ((/) [@id='Tcaptcha_iframe ' ) ]
驱动程序. 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 )。
可以按以下方式操作官方文档介绍:
来自selenium import web驱动程序
driver=webdriver.Chrome (
driver.get (https://crossbrowsertesting.github.io/drag-and-drop ) )
source ele=driver.find _ element (by.id,' draggable ' ) ) ) )。
target ele=driver.find _ element (by.id,' droppable ' ) ) ) ) ) )。
targetelexoffset=target ele.location.get (
targeteleyoffset=target ele.location.get (
webdriver.actionchains(driver ).drag _ and _ drop _ by _ offset (source ele,targetEleXOffset,targetEleYOffset )
但是,实际操作使用location.get () )的方法,运行后报告了:
/users/lifeng/python-virtualenv/venv/bin/python3/users/lifeng/python-projects/test-python/selenium
跟踪后台(mostrecentcalllast ) :
file '/users/lifeng/python-projects/test-python/selenium _ script.py ',line 29,in module
xoffset=code _ offset.location (170 )
typeerror : ' dict ' objectisnotcallable
进程完成退出代码1
release
释放按下的鼠标左键
导入时间
来自selenium import web驱动程序
from selenium.web driver.com mon.action _ chainsimportactionchains
withwebdriver.Chrome () asdriver:
driver.get (https://www.run OOB.com/python/python-tutorial.html ) )
text _ python=driver.find _ element _ by _ XPath ('/* [ @ rel=' noopenernoreferrer ' andtext ) )='Python 3.X
target _ python=driver.find _ element _ by _ XPath ('/* [ @ rel=' noopenernoreferrer ' andtext ) ]='python3
webdriver.actionchains,driver,click_and_hold,text_python,move_to_element,target_python )
web driver.action chains (driver.release ) (.perform ) )。
time.sleep(1) )。
以上总结或许能帮助到你,或许帮助不到你,但还是希望能帮助到你