Selenium3 解决登录界面滑块验证问题

1、JQuery 滑块解锁验证 — 实验用网页

https://www.helloweba.com/demo/2017/unlock/

 

2、实现 JQuery 滑块解锁验证代码

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

driver = webdriver.Chrome()
driver.get("https://www.helloweba.com/demo/2017/unlock/")
#定位第一个滑块
dragger = driver.find_elements_by_class_name("slide-to-unlock-handle")[0]

action = ActionChains(driver)
#通过click_and_hold()方法对滑块按下鼠标左键
action.click_and_hold(dragger).perform()  #鼠标左键按下不放

for index in range(200):
    try:
        #接下来就是通过for循环动滑块的位置,
        #move_by_offset()方法:第一个参数是X轴,
        #第二个参数是Y轴,单位为像素。因为是平行移动,
        #所以Y设置为0,X每次移动两2个像素。
        action.move_by_offset(2, 0).perform() #平行移动鼠标
    except UnexpectedAlertPresentException:
        break   #当解锁成功后会抛UnexpectedAlertPresentException异常,捕捉后跳出循环。
    action.reset_actions()  #清除之前的action
    sleep(0.1)  #等待停顿时间

# 打印警告框提示
success_text = driver.switch_to.alert.text
print(success_text)
sleep(3)
driver.quit()

 

3、JQuery 滑块解锁验证成功

 

参考至:https://www.cnblogs.com/fnng/p/7235498.html

转载于:https://www.cnblogs.com/test-postman/p/10164279.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值