How can I perform a left click and drag to right slide (with approximately 1 second transition time) with selenium in python.
Before drag
<div style="display:inline-block;" tabindex="11" id="continueId">
<button type="submit" style="left: 0px; top: 0px;">move me<span > →</span></button>
<label>drag to continue</label>
</div>
After drag
<div style="display:inline-block;" tabindex="11" id="continueId">
<button type="submit" style="left: 123px; top: 0px;">move me<span > →</span></button>
<label>drag to continue</label>
</div>
python: 3.11.1, ChromeDriver: 109.0.5414.74, Selenium: 4.8.0
CodePudding user response:
Have you tried 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.