问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/15783528/native-events-error-trying-to-double-click-element-using-watir-webdriver