【问题标题】:Python Selenium Drag and DropPython Selenium 拖放
【发布时间】:2013-06-07 00:36:59
【问题描述】:

我知道已经有其他相关的帖子,但没有一个给出完整的答案。下面是我正在使用的拖放代码:

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代码?)有关,但不知道是什么。

【问题讨论】:

    标签: python drag-and-drop webdriver


    【解决方案1】:

    您正在尝试拖放它是正确的。但实际的网址是 :http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop

    第二件事是两个 id 都在一个框架内,所以你必须在 perform() 之前先 *switch_to_frame*

    【讨论】:

      【解决方案2】:

      我也尝试过让它工作,但似乎 switch_to_frame 似乎没有帮助。一些额外的研究让我想到也许 Selenium WebDriver 不完全支持 HTML 5 拖放?

      https://code.google.com/p/selenium/issues/detail?id=3604

      我要看看能否找到一个不错的 jquery 拖放测试页面,我可以使用它来测试 iframe 的行为。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多