[英]how to perform left click and drag to right slide button with selenium in python
How can I perform a left click and drag to right slide (with approximately 1 second transition time) with selenium in python.如何在 python 中使用 selenium 执行左键单击并拖动到右滑(大约 1 秒的过渡时间)。
Before drag拖动前
<div style="display:inline-block;" tabindex="11" class="slide-submit" id="continueId">
<button type="submit" class="ui-draggable ui-draggable-handle" style="left: 0px; top: 0px;">move me<span class="arrow-right"> →</span></button>
<label>drag to continue</label>
</div>
After drag拖动后
<div style="display:inline-block;" tabindex="11" class="slide-submit" id="continueId">
<button type="submit" class="ui-draggable ui-draggable-handle ui-draggable-dragging" style="left: 123px; top: 0px;">move me<span class="arrow-right"> →</span></button>
<label>drag to continue</label>
</div>
python: 3.11.1, ChromeDriver: 109.0.5414.74, Selenium: 4.8.0 python:3.11.1,ChromeDriver:109.0.5414.74,Selenium:4.8.0
Have you tried action_chains
你有没有试过
action_chains
import进口
from selenium.webdriver.common.action_chains import ActionChains
Element to drag要拖动的元素
drag_element = driver.find_element_by_class_name("ui-draggable")
Perform the drag执行拖动
action = ActionChains(driver)
action.click_and_hold(drag_element)
action.move_by_offset(125, 0)
action.release().perform()
Note: Try the offset X
and Y
according to need.注意:根据需要尝试偏移
X
和Y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.