1

I'm using watir-webdriver with chrome to automate my tests and I'm kinda stuck now. I have a form inside a facebox(defunkt.io/facebox). There are many checkboxes inside this form as you can see:

irb(main):113:0> b.checkboxes.size
=> 122

My problem is when i try to set one of this checkboxes I get the following error:

irb(main):111:0> b.checkbox(:id => 'week_0').set 1
Selenium::WebDriver::Error::UnknownError: Element is not clickable at point (-99999800, 242.5)
Backtrace:
    0x8088d3a
    0x8076225
    0x807c718
    0x807c9e7
    0x807f6b7
    0x808009d
    0x8067c5c
    0x8074931
    0x8059fda
    0x80d1d4d
    0x80d3773
    0x80d3aa3
    start_thread [0x5e9e99]
    0x10b973e

from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/response.rb:50:in `assert_ok'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/http/common.rb:58:in `new'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/http/common.rb:58:in `create_response'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/http/common.rb:39:in `call'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/bridge.rb:450:in `raw_execute'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/bridge.rb:428:in `execute'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/remote/bridge.rb:264:in `clickElement'
from /usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.14.0/lib/selenium/webdriver/common/element.rb:34:in `click'
from /usr/local/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.3.9/lib/watir-webdriver/elements/checkbox.rb:25:in `set'
from (irb):111
from /usr/local/bin/irb:12:in `<main>'

What should I do to handle facebox with watir-webdriver on chrome?

EDIT:

I found the problem with a TIP from Chuck (look elements attribute at inspect element tool). So I noticed the checkboxes had -999999px left position.

Solution:

browser.execute_script("$('[type=checkbox]').removeClass('ui-helper-hidden-accessible')")

(since this was the class that was causing the left negative shift)

Pabluez
  • 2,653
  • 3
  • 19
  • 29
Lucas Castro
  • 21
  • 1
  • 6
  • Show us the HTML code that causes the error. Better yet, link to the page. – Željko Filipin Dec 06 '11 at 20:29
  • Which facebox? the mootools [http://www.bertramakers.com/moolabs/facebox.php]based one? the defunkt j-query [http://defunkt.io/facebox/] one? The lightbox tool from DynamicDrive [http://www.dynamicdrive.com/dynamicindex4/facebox/index.htm] – Chuck van der Linden Dec 06 '11 at 21:41
  • it is http://defunkt.io/facebox/ ill try to provide an online version so you can see the real example – Lucas Castro Dec 07 '11 at 19:07
  • This is a webdriver error really, so updated title to make that a bit more obvious and maybe get some input from some webdriver experts. – Chuck van der Linden Dec 08 '11 at 20:25
  • Can you use the developer tools (right click on it and select 'inspect element' in chrome) and determine what the properties of the element are? specifically I'm thinking things like position, left, top, display, etc. – Chuck van der Linden Dec 12 '11 at 21:52
  • The other thing to check is that there is not more than one of these things and maybe you are just finding one that is off-screen. at the point this thing is there on the screen, from IRB what value do you get back for b.checkboxes(:id => 'week_0').size – Chuck van der Linden Dec 12 '11 at 21:56
  • Hi, i've checked the attributes and the left attribute is -99999999px it is visible but off the screen and i guess that is causing the error – Lucas Castro Dec 13 '11 at 22:59

3 Answers3

1

I found the problem with a TIP from Chuck (look elements attribute at inspect element tool). So I noticed the checkboxes had -999999px left position.

Solution:

browser.execute_script("$('[type=checkbox]').removeClass('ui-helper-hidden-accessible')")

(since this was the class that was causing the left negative shift)

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Lucas Castro
  • 21
  • 1
  • 6
0

Try this. It will move the element into view using Javascript. Worked for me.

module Watir
  class Element
    def move_into_view
      browser.execute_script(%Q[
        var element = arguments[0];
        element.style.position = 'absolute';
        element.style.left = '10px';
        element.style.top = '10px';
        return true;],
        self )
    end
  end
end
joost
  • 6,549
  • 2
  • 31
  • 36
0

The error makes me think the thing may not be visible or active somehow. Is the script actually displaying the lightbox at the time it tries to interact with it? Do you need to insert a brief pause or wait for the checkbox to get rendered and the javascript code that 'pops up' the lightbox to finish it's thing?

If it is not visible then I could see it producing an error of the sort you are getting. Likewise if the script is just going a little too quick, that could be the issue also.

Use the developer tools (in chrome you can right click an element and choose 'inspect element') and look at the properties (specifically position) of the element in question, and the elements further up the 'tree' (as it were) that contain it.

You might be able to brute force around this by changing the class, or altering the CSS for the class to temporarily to 'relocate' the object such that Watir believes it is visible. I've had to do something similar for stuff that used the hover state to hide or show menus, where for whatever reason 'onmouseover' events were not good enough for the browser to apply a different css psuedoclass. If you are already using jquery there's some pretty simple functions that can be called to do that sort of thing. (one of your devs might be able to help you out with it) You can use .execute_script to invoke code like that if it's needed.

Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43
  • i'll give it a try, but the exception was kinda clear about "Element is not clickable at point (-99999800, 242.5)" – Lucas Castro Dec 08 '11 at 01:00
  • thanks for trying to help me! really, i also tried to use click_no_wait but it doesn't work at webdrive... I'll try to pause too. – Lucas Castro Dec 08 '11 at 01:01
  • the dead givaway of a timing issue is typically if it will work from IRB when you enter stuff a line at a time, but not when run from a script. That's when you may need to have the script wait for an element to be in a specific state, like visible. The coordinates in the error make me wonder if it is located 'off screen' which is a common tactic to 'hide' things if you don't want to use the 'display' property. – Chuck van der Linden Dec 08 '11 at 01:06
  • i was using IRB to test. Maybe you are right and we can discard timing issues – Lucas Castro Dec 08 '11 at 01:15
  • if you are entering a line at a time, then yes most likely. If you are cutting and pasting multiple lines, perhaps not. I think we need input from someone who knows the guts (and real meaning of the errors) of webdriver better than I do to make sense of that error. – Chuck van der Linden Dec 08 '11 at 20:20
  • unless something is glacially slow, that generally rules out this being some kind of timing issue – Chuck van der Linden Dec 13 '11 at 19:02
  • 1
    Hi Chuck, the 'developer tools' tip helped me a lot. I solved my problem, as i removed the class that shifts the element -9999999px to the left i was able to click at it. Could you please update your answer so i vote for it? – – Lucas Castro Dec 19 '11 at 20:37
  • Hmmm there must be some trick of 'relative' location going on there then.. interesting. Part of me wonders if this is a bug in how the visibility of an object is calculated. MAN I wish I could see and play with this page to figure out what's going on. If this is a watir or webdriver issue I'd like to see it fixed. – Chuck van der Linden Dec 19 '11 at 20:50