HTML5 Drag and Drop using Selenium Webdriver for Ruby

前端 未结 3 540
心在旅途
心在旅途 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 04:18

    Here is a temporary workaround that could help the community with testing in the meantime...

    1) drag_and_drop_helper.js(https://gist.github.com/2362544) to your test/helpers directory

    2) Create a new method in your test_helper.rb

     def drag_and_drop(source,target)
    
       js_filepath=File.dirname(__FILE__)+"/drag_and_drop_helper.js"
       js_file= File.new(js_filepath,"r")
       java_script=""
    
      while (line=js_file.gets)
        java_script+=line
       end
    
       js_file.close
    
       @driver.execute_script(java_script+"$('#{source}').simulateDragDrop({ dropTarget: '#{target}'});")
    
       rescue Exception => e
         puts "ERROR :" + e.to_s
    
    end
    

提交回复
热议问题