我有时使用 ActionsChains 时遇到任何问题,今天它不起作用,你知道为什么吗?
scrolling_bar = driver.find_element(By.CSS_SELECTOR, "#scrolling_bar")
start = scrolling_bar.location
ActionChains(driver)\
.drag_and_drop_by_offset(scrolling_bar, start['x'], start['y'] - 1000)\
.perform()
print('This message never be said')
ActionChains(driver).reset_actions()
动作已执行但停止我的程序
使用显式等待来确保元素在与其交互之前可见。 尝试
click_and_hold
、move_by_offset
,然后释放而不是 drag_and_drop_by_offset
。
driver = webdriver.Firefox()
driver.get('YOUR_URL_HERE')
scrolling_bar = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "#scrolling_bar"))
)
actions = ActionChains(driver)
actions.click_and_hold(scrolling_bar).move_by_offset(0, -1000).release().perform()
print('Drag and drop performed')
driver.quit()