1
votes

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)

3
Show us the HTML code that causes the error. Better yet, link to the page. - Ċ½eljko Filipin
Which facebox? the mootools [bertramakers.com/moolabs/facebox.php]based one? the defunkt j-query [defunkt.io/facebox/] one? The lightbox tool from DynamicDrive [dynamicdrive.com/dynamicindex4/facebox/index.htm] - Chuck van der Linden
it is defunkt.io/facebox ill try to provide an online version so you can see the real example - Lucas Castro
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
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

3 Answers

1
votes

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)

0
votes

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.

0
votes

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