selenium 滑动解锁(drag_and_drop_by_offset)
Posted 不吃西红柿a
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了selenium 滑动解锁(drag_and_drop_by_offset)相关的知识,希望对你有一定的参考价值。
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import UnexpectedAlertPresentException
from time import sleep
driver = webdriver.Firefox() driver.get("https://www.helloweba.com/demo/2017/unlock/")
#获取元素
dragger = driver.find_elements_by_class_name("slide-to-unlock-handle")[0]
action = ActionChains(driver)
#鼠标左键按下不放
action.click_and_hold(dragger).perform()
#平行移动大于解锁的长度的距离
try:
action.drag_and_drop_by_offset(dragger,500, 0).perform()
except UnexpectedAlertPresentException:
print("faild")
#等待2秒,方便捕捉弹框
sleep(2)
# 打印警告框提示
tt=driver.switch_to_alert()
success_text = tt.text
print(success_text)
#点击弹框中的ok按钮
tt.accept()
sleep(2)
driver.quit()
以上是关于selenium 滑动解锁(drag_and_drop_by_offset)的主要内容,如果未能解决你的问题,请参考以下文章