尝试使用watir-webdriver双击元素的Native Events错误 [英] Native Events error trying to double-click element using watir-webdriver

查看:204
本文介绍了尝试使用watir-webdriver双击元素的Native Events错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为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 /表/ TBODY [ 2] / tr [1] / td [1] / div')。double_click 

被执行我得到如下错误:

  test_search(TC_article_example):Selenium :: WebDriver :: Error :: InvalidElementStateError:无法执行本机互动:无法加载本地事件组件。 

[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:在`FirefoxDriver.prototype.mouseMove'
[远程服务器]文件中:/// C:/Users/TOMASZ~1.RYB/AppData/ Local/Temp/webdriver-profile20130403-4556-12yrrcd/extensions/fxdriver@googlecode.com/components/command_processor.js:10275:在`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-profile201304 03-4556-12yrrcd/extensions/fxdriver@googlecode.com/components/command_processor.js:10220:在`DelayedCommand.prototype.execute /'
C:/Ruby193/lib/ruby/gems/1.9。 1 / gems / selenium-webdriver-2.31.0 / lib / selenium / webdriver / remote / response.rb:52:在`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:在`new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver -2.31.0 / lib / selenium / webdriver / remote / http / common.rb:59:在`create_response'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver- 2.31.0 / lib / selenium / webdriver / remote / http / default.rb:66:在`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 /硒/ webdr iver / remote / bridge.rb:616:在`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:在`mouseMoveTo'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/mouse.rb:54 :在'move_to'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdriver/common/action_builder.rb:344:在` block in in'
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:在'hover'
C :/Watir/polisy.rb:27:在`test_search'$中b $ b

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

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

请给我点小费。我使用硒2.31 watir 4.0 firefox 19.0.2
PS:对不起我的英语。

解决方案

这个错误听起来像是想要本地事件,而且你正在禁止它们。尝试将本机事件的配置文件设置更改为true

还会丢弃丑陋,脆弱,无法读取xpath的内容。 Watir有更多的可读性,不太易碎的方法来识别你要点击的div。



开始一个新问题,包括一些HTML表格,其中div生活,你如何选择它的逻辑(当然,它涉及到表格的内容,而不仅仅是第三个表格第二行的第二个单元格),我们可以给你一些关于如何更好地选择元素的建议导致代码有意义并且可读,如果表格内容稍微改变,则不会中断,并且不会在对网页进行最轻微的重新设计时破坏。

I am writting automatic test for GWT application. And I try to double click on table element. I am using this code fo click:

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

When this command is executed I get error like:

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'

I have added this code to my script but this didn't help:

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

Please give me some tip. I use selenium 2.31, watir 4.0 and firefox 19.0.2. PS: Sorry for my english.

解决方案

The error sounds like it wants native events, and you are disallowing them. try changing the profile setting for native events to true

Also ditch the ugly, brittle, impossible to read xpath. Watir has far more readable, less brittle ways to identify the div you are trying to click.

Start a new question, include some of the HTML for the table where that div lives, the logic for how you are picking it (surely it relates to the content of the table? not just second cell of the second row of the third tablebody) and we can give you some advice on how to better select the element that will result in code that makes sense and is readable, won't break if the table contents change slightly, and won't break at the slightest re-design of the page.

这篇关于尝试使用watir-webdriver双击元素的Native Events错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆