0

我正在尝试使用 Selenium WebDriver 和 Ruby 实现拖放功能。为了实现这一点,我做了以下工作:

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox

driver.get "myurl"

source = driver.find_element(:id, '19026240')
target = driver.find_element(:xpath, "//div[@id='rootLabelChildren']/div/div")

driver.action.drag_and_drop(source, target).perform

这不会导致任何错误,例如无法定位元素、未附加到 DOM 的元素等。但这会导致超时错误:

Timeout::Error: Timeout::Error
        from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill'
        from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
        from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
        from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1293:in `request'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1286:in `block in request'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:745:in `start'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1284:in `request'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for
'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:629:in `raw_execute'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:607:in `execute'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:394:in `mouseMoveTo'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/mouse.rb:54:in `move_to'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/action_builder.rb:344:in `block in
perform'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/action_builder.rb:343:in `each'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/action_builder.rb:343:in `perform'
        from (irb):6
        from C:/Ruby193/bin/irb:12:in `<main>'irb(main):007:0> end
SyntaxError: (irb):7: syntax error, unexpected keyword_end
        from C:/Ruby193/bin/irb:12:in `<main>'

手动,拖放工作正常。超时错误的原因可能是什么?

Firefox 版本:21 Selenium WebDriver:2.33.0

HTML 代码:

对于目标

<div id="rootLabelChildren" class="children">
<div class="label " labelid="74ce292d65844af7b4e480782d8e9b38" labelname="0106">
<div class="labelName terminal" draggable="true">0106</div>
<div class="children"> </div>
</div>

对于源

<table class="dataGridHeader">
<div class="dataGridScrollbarContainer scrollable" style="">
<div class="dataGridContents" style="min-height: 12880px;">
<table class="buffer" style="margin-top: 0px;">
<tbody>
<tr id="19026240" class="selected" draggable="true">
4

1 回答 1

0

根据变更日志

Selenium WebDriver:2.33.0不支持Firefox 版本:21。因此将其降级为Firefox version: 19Firefox version: 20

这将处理错误:rescue in rbuf_fill

要拖放元素,请尝试以下操作:

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get "myurl"
source = driver.find_element(:css, 'tr#19026240')
target = driver.find_element(:css, 'div#rootLabelChildren>div>div')
driver.action.drag_and_drop(source, target).perform

对于您的拖放功能,我得到了一个很好的链接HTML5 Drag and Drop with Selenium Webdriver。它会帮助你。

于 2013-07-18T08:36:11.390 回答