Nutty, I know, but try forcing a scroll of the element into the visible portion 
of the browser before doing the hover. I was doing something similar and 
noticed I was getting failures when the thing I was trying to interact with was 
outside of the viewable area or the browser was minimized. This was with Chrome 
but the problem sounds similar. Maybe something to do with native events.

$b.driver.action.move_to(some_element_above_the_one_you_want.wd).perform


And maybe try a pause after the hover if the scroll thing doesn't work.



________________________________
 From: Mont Rothstein <[email protected]>
To: [email protected] 
Sent: Tuesday, July 16, 2013 2:40 PM
Subject: [wtr-general] Intermittent failure of when_present
 


I am getting intermittent failures of when_present.  I can't figure out how to 
resolve them.

Environment:
IE 10 (Browser mode: IE10 Compat View, Document mode: IE7 standards)
ruby 2.0.0p247 (2013-06-27) [x64-mingw32]

watir (4.0.2)
watir-webdriver (0.6.4)
selenium-webdriver (2.33.0)


Failing code:
def select_menu_item(top_level_menu, menu_item_text)
>    parent_menu = $b.li(:id, top_level_menu)
>    parent_menu.when_present.hover
>
>
>    menu_item_text.gsub!(' ', '( | )') # replace space with a regex for either 
>space or non-breaking space
>    parent_menu.when_present.link(:text, 
>/#{menu_item_text}/).when_present.fire_event('onClick')
>
>
>    $b.body.when_present.hover #unhover the menu
>end

The specific lines that sometimes fail are:

    parent_menu.when_present.hover


and

    $b.body.when_present.hover #unhover the menu


The first one causes the CSS menu to drop down.  The second one hides it again. 
 The fire_event line used to intermittently fail as well but the two 
when_present calls seem to have squelched that.

The error I'm getting is:

Selenium::WebDriver::Error::JavascriptError: Error determining if element is 
displayed
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/response.rb:51:in
> `assert_ok'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/response.rb:15:in
> `initialize'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:59:in
> `new'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:59:in
> `create_response'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:66:in
> `request'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:40:in
> `call'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:629:in
> `raw_execute'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:607:in
> `execute'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:548:in
> `isElementDisplayed'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/element.rb:171:in
> `displayed?'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:387:in
> `visible?'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:398:in
> `present?'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/wait.rb:98:in
> `block in method_missing'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/wait.rb:25:in
> `until'
>    
>C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/wait.rb:98:in
> `method_missing'

The select_menu_item method is being called multiple times during a test and 
the test is being looped over multiple times.  Each loop starts a new browser 
session ($b = Watir::Browser.start(url, :ie)and $b.close).

I was getting these intermittent failures before I started creating and closing 
the session on each pass through the test loop.

Any ideas on what I am doing wrong and/or what I can do to resolve this?

Thanks,
-Mont

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.
 
[email protected]
http://groups.google.com/group/watir-general
[email protected]
 
--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to