Hi Gary,

#exist? returns true if the element is in the DOM
#visible? and #present? both attempt to return whether a user can see the 
element. (the difference being that #visible? will raise an exception if 
the element does not already exist; so for most purposes you should use 
#present?)

This is what the W3C spec has to say about visibility: 
https://w3c.github.io/webdriver/webdriver-spec.html#element-displayedness
Here is David Burns from Mozilla at the Selenium Conference talking about 
the difficulties: https://www.youtube.com/watch?v=hTa1KI6fQpg

Right now there is a complicated javascript chunk (isDisplayed.js) built by 
the Selenium project that the browser vendors use in their drivers to give 
the best possible guess at an element being displayed.

Visibility and Clickability are different as well. 
When attempting to interact with an element, Selenium brings that element 
into the viewport and then attempts to click in the center of the 
element: 
https://w3c.github.io/webdriver/webdriver-spec.html#dfn-in-view-centre-point

If that center is covered up by another element, you'll get the "element 
not clickable" error, even if it is only partially covered. (You see this a 
lot with the static headers). This is where watir-scroll comes in handy, 
because you can move the element you want to interact with out from behind 
fixed elements on the page.

With all of that out of the way, we get to your comment about "off the 
bottom of the page." No errors have ever gotten thrown for this condition. 
If the element was not being automatically brought into the viewport then 
it was a bug not a feature. :)

For functional tests we typically don't distinguish between actually on the 
screen and able to be brought into the screen for an action to take place.
There are probably some things we could do using 
https://w3c.github.io/webdriver/webdriver-spec.html#get-element-rect 
and https://w3c.github.io/webdriver/webdriver-spec.html#get-window-size to 
process whether the current viewport needs to be moved in order to see the 
element, but I'm not sure I see the value in it. What is your use case?

Titus


On Monday, November 28, 2016 at 3:58:14 AM UTC-8, gary wrote:
>
> A question which i've found cropping up in a few places and at times 
> appears controversial, not sure why, but i'm also struggling to find an 
> answer for, and in the absence of an answer how does anybody else do this.
> To put it simply how to confirm if an element is in the users viewport, 
> not if it exists on the page but can the user see it?
> The previous incarnation of webdriver in firefox would return an element 
> is not clickable type message if you tried to click an item which was off 
> the bottom of the page, meaning i'd use watir-scroll to interact with it. 
> That indicates to me that somehow, somewhere there is a way to identify it, 
> or there used to be?  The latest versions of the drivers mean that chrome 
> and firefox both don't seem to care and will just click it anyway.
> Ideally i'd be using this in conjuction with chromes mobile_emulation so i 
> need to be able to identify if in mobile view, certain elements are in view.
> Any thoughts and ideas as usual would be greatly appreciated.
> Cheers, G
>

-- 
-- 
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/d/optout.

Reply via email to