0

我正在为 GWT 应用程序编写自动测试。我尝试双击表格元素。我正在使用此代码单击:

browser.element(:xpath, '/html/body/div[5]/div[2]/div/div/div/div[2]/div/div/div/div/div/div/div/div[2]/div/div[2]/div/div/table/tbody[2]/tr[1]/td[1]/div').double_click

执行此命令时,我收到如下错误:

test_search(TC_article_example):Selenium::WebDriver::Error::InvalidElementStateError: Cannot perform native interaction: Could not load native events component.

[remote server] file:///C:/Users/TOMASZ~1.RYB/AppData/Local/Temp/webdriver-profile20130403-4556-12yrrcd/extensions/fxdriver@googlecode.com/components/driver_component.js:8577:in `generateErrorForNativeEvents'
[remote server] file:///C:/Users/TOMASZ~1.RYB/AppData/Local/Temp/webdriver-profile20130403-4556-12yrrcd/extensions/fxdriver@googlecode.com/components/driver_component.js:8610:in `FirefoxDriver.prototype.mouseMove'
[remote server] file:///C:/Users/TOMASZ~1.RYB/AppData/Local/Temp/webdriver-profile20130403-4556-12yrrcd/extensions/fxdriver@googlecode.com/components/command_processor.js:10275:in `DelayedCommand.prototype.executeInternal_/h'
[remote server] file:///C:/Users/TOMASZ~1.RYB/AppData/Local/Temp/webdriver-profile20130403-4556-12yrrcd/extensions/fxdriver@googlecode.com/components/command_processor.js:10280:in `DelayedCommand.prototype.executeInternal_'
[remote server] file:///C:/Users/TOMASZ~1.RYB/AppData/Local/Temp/webdriver-profile20130403-4556-12yrrcd/extensions/fxdriver@googlecode.com/components/command_processor.js:10220:in `DelayedCommand.prototype.execute/<'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/bridge.rb:616:in `raw_execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/bridge.rb:594:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/remote/bridge.rb:389:in `mouseMoveTo'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/mouse.rb:54:in `move_to'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/action_builder.rb:344:in `block in perform'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/action_builder.rb:343:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/action_builder.rb:343:in `perform'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.2/lib/watir-webdriver/elements/element.rb:181:in `hover'
C:/Watir/polisy.rb:27:in `test_search'

我已将此代码添加到我的脚本中,但这没有帮助:

profile = Selenium::WebDriver::Firefox::Profile.new
profile.native_events = false
browser = Watir::Browser.new :firefox, :profile => profile

请给我一些提示。我使用selenium 2.31watir 4.0firefox 19.0.2。PS:对不起我的英语。

4

1 回答 1

0

该错误听起来像是需要本地事件,而您不允许它们。尝试将本机事件的配置文件设置更改为 true

还抛弃了丑陋、脆弱、无法阅读的 xpath。Watir 有更易读、更简单的方法来识别您尝试单击的 div。

开始一个新问题,包括该 div 所在表格的一些 HTML,以及您如何选择它的逻辑(当然它与表格的内容有关?不仅仅是第三个表格的第二行的第二个单元格)我们可以给你一些建议,告诉你如何更好地选择元素,这些元素将产生有意义且可读的代码,如果表格内容发生轻微变化也不会中断,并且不会因为稍微重新设计而中断页。

于 2013-04-03T18:03:38.670 回答