滑块作为安全验证机制的一种,经常在登录或者注册时涉及。但是在自动化测试时,需要想办法用代码的方式来处理滑块。
selenium中对滑块的操作基本是采用元素拖曳的方式,而这种方式需要用到selenium的Actionchains功能模块的drag_and_drop_by_offset方法。
示例:以携程网的注册页面为例,URL:https://passport.ctrip.com/user/reg/home/
# coding = utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
# 打开chrome浏览器
d = we

本文介绍如何使用Selenium的ActionChains模块在携程注册页面实现滑块验证的自动化测试,通过XPath定位元素并进行拖曳操作。
最低0.47元/天 解锁文章
4621

被折叠的 条评论
为什么被折叠?



