Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Elements shifted off the page with negative locations are considered visible #951

Open
twalpole opened this issue Sep 21, 2016 · 9 comments

Comments

@twalpole
Copy link
Collaborator

When using capybara-webkit (and poltergeist)

<input id="radio_1" name="radio" value="1" type="radio", style="position:absolute; left: -9999px>

is considered a visible element, although it cannot be seen or interacted with (clicked, etc). Current selenium-webdriver (2.53.4) reports it as non-visible, although the 3.0.0.beta3.1 version reports it as visible but throws an ElementNotVisible error if you try to click it. Not really sure what the current outcome here is, although I lean towards that it should be non-visible.

@jferris
Copy link
Contributor

jferris commented Sep 21, 2016

Here's what we currently do for a click test: https://github.com/thoughtbot/capybara-webkit/blob/master/src/WebPage.cpp#L286

We could additionally check to see that the coordinates we're trying to click are on the screen (or can be scrolled to).

@mhoran
Copy link
Collaborator

mhoran commented Sep 21, 2016

We also check that the node is visible in this code:

isNodeVisible: function(node) {
while (node) {
var style = node.ownerDocument.defaultView.getComputedStyle(node, null);
if (style.getPropertyValue('display') == 'none' || style.getPropertyValue('visibility') == 'hidden')
return false;
node = node.parentElement;
}
return true;
},
which is called from Capybara.clickPosition.

@twalpole
Copy link
Collaborator Author

@jferris Yes - it currently errors correctly if one tries to click the element - the issue (if there is an issue) is that if #visible? is called on the element it returns true. I'm not sure whether or not that should be the case since the user can't usually scroll to negative positions to see the element.

@twalpole
Copy link
Collaborator Author

Note: this only came up because of the :allow_label_click option for checkboxes/radio buttons in Capybara 2.8+ which capybara-webkit doesn't yet support, and I'm working around it for a 2.9.1 release, but it would be nice to have a consensus on what the result of #visible? should be for these elements.

@jferris
Copy link
Contributor

jferris commented Sep 21, 2016

@mhoran if we used clickTest when asking if an element was visible, that would change the original example to return false, right?

@mhoran
Copy link
Collaborator

mhoran commented Sep 22, 2016

Yeah, I think so. Though something may be visible, but underneath another element, in which case clickTest would return false. So I guess we should just add bounds checking to isNodeVisible.

@jferris
Copy link
Contributor

jferris commented Sep 22, 2016

Hmm, actually, that's interesting: if something is obscured behind a modal dialog or something, is it visible?

@twalpole
Copy link
Collaborator Author

I believe selenium considers something visible if the user can scroll it into a position where it can be seen, so behind a modal could still be considered visible, of course that may be changing as selenium moves towards only supporting browsers through vendor provided drivers, and the webdriver spec solidifies.

@mhoran
Copy link
Collaborator

mhoran commented Sep 23, 2016

@jferris I was also thinking something along the lines of an overlaying semi-transparent (or completely transparent div), that allows the underling content to be visible, but not clickable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants