Python Selenium WebDriver 拖放 [英] Python Selenium WebDriver drag-and-drop
本文介绍了Python Selenium WebDriver 拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用 Python WebDriver 绑定进行拖放操作.我正在 Mac OS X 上使用 Google Chrome 和 Firefox.这里有一个线程有人遇到过类似的问题.
I cannot get drag-and drop working with the Python WebDriver bindings. I am working with Google Chrome and Firefox on Mac OS X. There is a thread here where someone had a similar problem.
我尝试过使用 ActionsChains
:
from selenium import webdriver
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
actionChains = ActionChains(driver)
actionChains.drag_and_drop(source, target).perform()
您是否设法让 Python WebDriver 拖放工作?
Have you managed to get the Python WebDriver drag-and-drop working?
推荐答案
为了提供更新的答案,我已经验证这实际上现在在 Mac 上有效.
For the sake of giving an updated answer, I have verified that this does in fact work on Mac now.
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Firefox()
driver.get("your.site.with.dragndrop.functionality.com")
source_element = driver.find_element_by_name('your element to drag')
dest_element = driver.find_element_by_name('element to drag to')
ActionChains(driver).drag_and_drop(source_element, dest_element).perform()
这篇关于Python Selenium WebDriver 拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文