Selenium3自动化测试——17.控制滑动解锁

本文介绍了如何使用Selenium3实现网页滑动解锁的自动化测试。通过定位滑动块,点击并按住,然后移动鼠标来模拟滑动过程。在测试中,滑块以0.1秒的间隔平稳滑动,最终成功解锁并触发解锁成功提示。
摘要由CSDN通过智能技术生成

1. 实现目标

打开https://www.helloweba.net/demo/2017/unlock/,自动测试鼠标放置在滑块上,实现自动滑动。

2. 实现代码

其中,获得某个具体额滑动块,可找到所有class_name为slide-to-unlock-handle的,选择第0-第3项;

click_and_hold():单击并按下鼠标左键;

move_by_offset():移动鼠标,第一个参数为x坐标距离,第二个参数为y坐标距离;

reset_action():重置action。

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

driver = webdriver.Chrome()
driver.get("http://www.helloweba.com/demo/2017/unlock/")

# 定位滑动块
slider = driver.find_elements_by_class_name("slide-to-unlock-handle")[1]
action = ActionChains(driver)
action.click_and_hold(slider).perform()

for index in range(200):
    try:
        action.move_by_offset(2, 0).perform()
  
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值