百科生活 投稿
关于【鼠标连点测试】,连点器速度测试,今天涌涌小编给您分享一下,如果对您有所帮助别忘了关注本站哦。
鼠标连点测试?鼠标表示鼠标事件鼠标操作是通过使用低级界面执行的,该界面允许我们向Web浏览器提供虚拟化的设备输入操作,接下来我们就来聊聊关于鼠标连点测试?以下内容大家不妨参考一二希望能帮到您!

鼠标连点测试
鼠标表示鼠标事件。鼠标操作是通过使用低级界面执行的,该界面允许我们向Web浏览器提供虚拟化的设备输入操作。
–
鼠标动作操作方法详细介绍如下:
click_and_hold
移动到该元素,然后在给定元素的中间单击(不释放)
import timefrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainswith webdriver.Chrome() as driver: driver.get('http://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 timefrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainswith webdriver.Chrome() as driver: driver.get('http://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 timefrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainswith webdriver.Chrome() as driver: driver.get('http://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 timefrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainswith webdriver.Chrome() as driver: driver.get('http://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 timefrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainswith webdriver.Chrome() as driver: driver.get('http://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.pyTraceback (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 timefrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainswith webdriver.Chrome() as driver: driver.get('http://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中要传两个参数,传入第一个是源元素setting后按住,再点击传入的目标元素setting_one后,然后再释放掉setting_one
drag_and_drop_by_offset
首先在源元素上单击并按住,移至给定的偏移量,然后释放鼠标。可针对验证码滑动解锁操作
import timefrom selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.common.exceptions import UnexpectedAlertPresentExceptionwith webdriver.Chrome() as driver: driver.get('http://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 webdriverdriver = webdriver.Chrome()driver.get("http://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.pyTraceback (most recent call last): File "/Users/lifeng/python-projects/test-python/selenium_script.py", line 29, inxOffset = code_offset.location(170)TypeError: 'dict' object is not callableProcess finished with exit code 1 release
将释放按下的鼠标左键
本文关键词:鼠标连点测试网站,鼠标连击测试,鼠标连点测试网页,鼠标连点速度多少最佳,鼠标连点测试怎么设置。这就是关于《鼠标连点测试,连点器速度测试》的所有内容,希望对您能有所帮助!
- 上一篇: 重神机潘多拉评分,石冢运升畅谈重神机潘多拉
- 下一篇: 计算机入门级基础知识图解,计算机基础知识
- 最近发表