selenium对滑块拖拉操作
在做登录测试时,有些站点会有“滑块”验证功能,自动化测试可用对滑块拖拉操作的方式处理:
- 需求:携程注册“滑块”操作
- 思路:
- 按住左边滑块
- 拖放到最右边
- 用键盘事件中:drag_and_drop_by_offset
- 代码为:
#大牛测试:轻轻松松自动化 #QQ:2574674466 #专注自动化测试技术传播 from selenium import webdriver import time from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains driver = webdriver.Chrome() driver.get("https://passport.ctrip.com/user/reg/home") driver.find_element_by_css_selector("#agr_pop > div.pop_footer > a.reg_btn.reg_agree").click() sour = driver.find_element_by_css_selector("#slideCode > div.cpt-drop-box > div.cpt-drop-btn") print(sour.size['width']) print(sour.size['height']) ele =driver.find_element_by_css_selector("#slideCode > div.cpt-drop-box > div.cpt-bg-bar") print(ele.size['width']) print(ele.size['height']) time.sleep(2) ActionChains(driver).drag_and_drop_by_offset(sour,ele.size["width"],-ele.size["height"]).perform()
- 视频、资料、代码、文档 请联系qq:2574674466
- 微信公众号“大牛测试”
欢迎加入交流群:Selenium学习群: 628908894