HTML5 Drag and Drop using Selenium Webdriver for Ruby

前端 未结 3 538
心在旅途
心在旅途 2020-12-18 03:32

Are there any work arounds to getting HTML5 Drag and Drop working with Selenium Webdriver with Ruby? I am using Selenium-Webdriver 2.20.0 with Ruby 1.9.2

Here is a

3条回答
  •  星月不相逢
    2020-12-18 03:55

    Here is how to get drag and drop (dnd) to work with Capybara/Selenium for cucumber tests. Basically calling dnd directly from Capybara using the drag_to method does not work. You have to drop out of Capybara into Selenium, and when using Selenium use click_and_hold method followed by drag_and_drop and then release for dnd to work. Here is the code:

    #jump out of capybara for dnd
    
    #selenium web driver accessed directly using page.driver.browser
    source_selenium_ele = page.driver.browser.find_element(:xpath, "//draggable-element")
    target_selenium_ele = page.driver.browser.find_element(:xpath, "//destination-element")
    
    #drag and drop actions
    page.driver.browser.action.click_and_hold(source_selenium_ele).perform
    page.driver.browser.action.drag_and_drop(source_selenium_ele, target_selenium_ele).perform
    page.driver.browser.action.release.perform
    
    #jump back into capybara...
    

提交回复
热议问题