我知道已经有其他相关的帖子,但没有一个给出完整的答案。贝娄是我正在使用的拖放代码:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
url = 'http://www.w3schools.com/html/html5_draganddrop.asp'
driver = webdriver.Firefox()
driver.get(url)
element = driver.find_element_by_id("drag1")
target = driver.find_element_by_id("div2")
ActionChains(driver).drag_and_drop(element, target).perform()
你能告诉我这段代码有什么问题吗?
稍后编辑:找到以下有效的示例:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
firefox = webdriver.Firefox()
firefox.get('http://www.theautomatedtester.co.uk/demo2.html')
draggable = firefox.find_element_by_class_name("draggable")
droppable = firefox.find_element_by_name("droppable")
dragdrop = ActionChains(firefox)\
.drag_and_drop(draggable, droppable)
dragdrop.perform()
它必须与页面源(js代码?)有关,但我不知道是什么。