Raise error when the driver tries to click an invisilbe element, like Selenium does #245

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
Contributor

marcofognog commented Jan 18, 2012

Also, I think its reasonable to add this to #drag_to, and every other mouse interaction to elements (that we might have in the future).

@jferris jferris commented on an outdated diff Jan 19, 2012

lib/capybara/driver/webkit/node.rb
@@ -46,7 +50,11 @@ def unselect_option
end
def click
- invoke "click"
+ if visible?
+ invoke "click"
+ else
+ raise ElementNotDisplayedError, "This element is not visible so it may not interacted with"
@jferris

jferris Jan 19, 2012

Owner

I think this should read "may not be interacted with."

@jferris jferris commented on an outdated diff Jan 19, 2012

spec/driver_spec.rb
@@ -662,6 +663,12 @@
subject.find("//*[@class='triggered']").should_not be_empty
end
+ it "raise error when it tries to click an invisible element" do
@jferris

jferris Jan 19, 2012

Owner

I think this should read "raises an error."

Owner

jferris commented Jan 19, 2012

I agree with what you said about other mouse events, and I think it should be extended to other UI events as well, such as filling in text fields. Is there a way we can handle this generically? For example, is it reasonable to say that all commands to invisible nodes should fail besides asking if they're visible?

Contributor

marcofognog commented Jan 19, 2012

I fixed the typos and added the same behavior for #drag_to and #select_option. I guess those (plus #click) are the UI events that need this kind of treatment, right?

Contributor

marcofognog commented Jan 23, 2012

About not asking the node if it is visible, I can`t thing of other way to do this.

Owner

jferris commented Jan 23, 2012

I'll think more about making this general, but I merged what you have in for now. Thanks for the patch!

jferris closed this Jan 23, 2012

I think there is a bug with this somewhere. Just updated Capybara-Webkit to include this and now I am getting not visible errors on a link within my navbar when it is definitely visible. Using twitter bootstrap for the navbar.

Using the javascript console (in web developer toolbar) the element is reported as visible. Still poking around...

Update: Additionally, the link is visible w/o javascript enabled. Therefore unsure why this is happening.

Contributor

marcofognog commented Feb 8, 2012

Could you please strip your code down to just what is not working and show us, so we can try to reproduce issue?

endymion commented Feb 8, 2012

I agree with rschmukler, I see the same thing. I've got links that are definitely visible, but I'm getting failing tests from this. My code uses jQuery Mobile, and if I comment out the CSS that makes a jQuery Mobile page "display: none;" initially, then I don't have this problem any more.

I'm getting the same thing:

http://travis-ci.org/shioyama/yogoshu

And like @rschmukler the element in question (a login button) is visible without javascript.

Contributor

halogenandtoast commented Feb 17, 2012

@rschmukler , @shioyama, @endymion : Could you guys try what capybara-webkit is doing to check for visibility. Something like this:

var element = $("a[href='/sign_in']")[0];
var visible = true;
while (element) {
  if (element.ownerDocument.defaultView.getComputedStyle(element, null).getPropertyValue("display") == 'none')
    visible = false;
  element = element.parentElement;
}

And let me know what the value of visible is. If it's false can you see if any of it's parent element are not visible for some reason?

voldy commented Feb 19, 2012

Same affected me.

@halogenandtoast: Visible is true here:

:javascript
  $(document).ready(function(){
    var element = $("a[href='/sign_in']")[0];
    var visible = true;
    while (element) {
      if (element.ownerDocument.defaultView.getComputedStyle(element, null).getPropertyValue("display") == 'none')
        visible = false;
      element = element.parentElement;
    }
    alert(visible);
  });

= simple_form_for(resource, url: session_url(resource_name)) do |f|
  = f.input :email
  = f.input :password
  = f.button :submit

I am getting it on ubuntu using headless gem.

Same error here.
I click an element that open a menu and makes links visibles.
While also capybara says element is visible clicking on that throw the error!!
Any workaround?

shioyama commented Mar 3, 2012

@halogenandtoast

I ran the test above and all parent elements have a "display" value of "inline-block", all are visible (it traces all the way back until element is null).

This problem only happens for me on Travis, when I run cucumber locally all tests pass. Something subtle must be different between the environments but I haven't been able to figure out what it is.

shioyama commented Mar 3, 2012

p.s. I think this pull request should be re-opened or an issue added to address the problems with visibility noted above.

jferris reopened this Mar 5, 2012

Owner

jferris commented Mar 5, 2012

I'm re-opening this issue so we can decide what needs to be done here.

I am seeing this issue as well with links that are definitely visible.

A workaround is to do:

  my_link = find_link "Click Me!"
  my_link.base.stub(:check_visibility) # HACK: https://github.com/thoughtbot/capybara-webkit/pull/245
  my_link.click

I think that hidden items should be touchable.
Is very common to use javascript that hide the real input creating a fancy visual layer . Ex: chosen

gicappa commented Mar 9, 2012

+1 andreacfm

Any news on this?
I am using hack to display any hidden field on my tests cause I use chosen and other fancy tool that hide the real inputs/selects ... but my hack is not robust and my tests are not solid anymore.
What is the version that introduced the visibility check?

Owner

jferris commented Mar 16, 2012

I reverted this in the latest release. We've decided to allow interaction with invisible elements.

jferris closed this Mar 16, 2012

Thanks for that. I was able to remove my workaround.

gicappa commented Mar 19, 2012

Thx from here too.

Obviously, youre visible? doesn't work correct. Have you ever thought about to fix that? Allowing to click on invisible elements sounds very weird to me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment