Methods to get element location(s)

874 views
Skip to first unread message

Alexei Barantsev

unread,
Dec 21, 2012, 4:08:52 PM12/21/12
to selenium-...@googlegroups.com
Hi, devs,

About two years ago Eran started rework of the advanced user interactions -- https://code.google.com/p/selenium/source/detail?r=11008 . He introduces a new method Locatable.getCoordinates() that should allow to get various kinds of element location info:
Locatable.getCoordinates().getLocationOnScreen()
Locatable.getCoordinates().getLocationInViewPort()
Locatable.getCoordinates().getLocationInDOM()

Only first of these methods was implemented -- RemoteWebElement.getCoordinates().getLocationOnScreen() is an alias for getLocationOnceScrolledIntoView()

Unfortunately, semantics of these methods was not defined, and I want to do this now.

I suggest the following:

1) getLocationOnScreen() should return location of the element relative to the top-left corner of the monitor (screen). The result can be used in the tools like Java AWT Robot to act (e.g. click) by coordinates.

2) getLocationInViewPort() should return location of the element relative to the top-left corner of the browser viewport or the frame that contains this element. The result can be used to do some actions by coordinates in JavaScript.

3) getLocationInDOM() -- I have no idea what was the intention of this method, de we need this at all? :)

And see a separate message about scrolling.

Regards,
-- 
Alexei Barantsev
Software-Testing.Ru
Selenium2.Ru

Jason Leyba

unread,
Dec 21, 2012, 4:24:27 PM12/21/12
to selenium-...@googlegroups.com
On Fri, Dec 21, 2012 at 1:08 PM, Alexei Barantsev <bara...@gmail.com> wrote:
Hi, devs,

About two years ago Eran started rework of the advanced user interactions -- https://code.google.com/p/selenium/source/detail?r=11008 . He introduces a new method Locatable.getCoordinates() that should allow to get various kinds of element location info:
Locatable.getCoordinates().getLocationOnScreen()
Locatable.getCoordinates().getLocationInViewPort()
Locatable.getCoordinates().getLocationInDOM()

These method names seem a little redundant.  Could we rename them?

getCoordinates().onScreen();
getCoordinates().inViewPort();

See comment below for InDOM.
 

Only first of these methods was implemented -- RemoteWebElement.getCoordinates().getLocationOnScreen() is an alias for getLocationOnceScrolledIntoView()

Unfortunately, semantics of these methods was not defined, and I want to do this now.

I suggest the following:

1) getLocationOnScreen() should return location of the element relative to the top-left corner of the monitor (screen). The result can be used in the tools like Java AWT Robot to act (e.g. click) by coordinates.

SGTM - what if the element is in a frame and not within view of parent?
 

2) getLocationInViewPort() should return location of the element relative to the top-left corner of the browser viewport or the frame that contains this element. The result can be used to do some actions by coordinates in JavaScript.

Lets avoid complications with frames and have this always be relative to element's viewport (element.ownerDocument.defaultView).
 

3) getLocationInDOM() -- I have no idea what was the intention of this method, de we need this at all? :)

This is probably intended to be relative to the overall structure of the page, independent of the viewport/scrolling.  If it's not used right now, let's delete it.
 

And see a separate message about scrolling.

Regards,
-- 
Alexei Barantsev
Software-Testing.Ru
Selenium2.Ru

--
 
 

Simon Stewart

unread,
Dec 23, 2012, 6:08:38 AM12/23/12
to selenium-...@googlegroups.com
On Fri, Dec 21, 2012 at 1:24 PM, Jason Leyba <jml...@gmail.com> wrote:
On Fri, Dec 21, 2012 at 1:08 PM, Alexei Barantsev <bara...@gmail.com> wrote:
Hi, devs,

About two years ago Eran started rework of the advanced user interactions -- https://code.google.com/p/selenium/source/detail?r=11008 . He introduces a new method Locatable.getCoordinates() that should allow to get various kinds of element location info:
Locatable.getCoordinates().getLocationOnScreen()
Locatable.getCoordinates().getLocationInViewPort()
Locatable.getCoordinates().getLocationInDOM()

These method names seem a little redundant.  Could we rename them?

getCoordinates().onScreen();
getCoordinates().inViewPort();

SGTM.
 
See comment below for InDOM.
 

Only first of these methods was implemented -- RemoteWebElement.getCoordinates().getLocationOnScreen() is an alias for getLocationOnceScrolledIntoView()

Which is wrong. *sigh* Yes, it should scroll the element into view, but the returned coordinates really should be the coordinates on the physical screen. "inViewPort()" would cover the case for the viewport.
 
Unfortunately, semantics of these methods was not defined, and I want to do this now.

I suggest the following:

1) getLocationOnScreen() should return location of the element relative to the top-left corner of the monitor (screen). The result can be used in the tools like Java AWT Robot to act (e.g. click) by coordinates.

SGTM - what if the element is in a frame and not within view of parent?

The "screen" bit is important: we're calculating where the pixels are so that an external process can click on it. If we can't pull those pixels on to the screen, we should throw an ElementNotVisibleException in this case.
 

2) getLocationInViewPort() should return location of the element relative to the top-left corner of the browser viewport or the frame that contains this element. The result can be used to do some actions by coordinates in JavaScript.

Lets avoid complications with frames and have this always be relative to element's viewport (element.ownerDocument.defaultView).

Hmmm... one argument for this is that we're thinking of the area visible within the browser window as the viewport, rather than the defaultView. This method is generally used for firing OS-level events, so it may be relative to whatever OS-window is being used to display the content. This means that the details may well be different between browsers and OSs. Perhaps we need a different name?
 

3) getLocationInDOM() -- I have no idea what was the intention of this method, de we need this at all? :)

This is probably intended to be relative to the overall structure of the page, independent of the viewport/scrolling.  If it's not used right now, let's delete it.

It's a synonym for WebElement.getLocation(). I'd suggest just delegating down to that.
 
Simon

And see a separate message about scrolling.

Regards,
-- 
Alexei Barantsev
Software-Testing.Ru
Selenium2.Ru

--
 
 

--
 
 

Alexei Barantsev

unread,
Jan 27, 2013, 10:16:24 AM1/27/13
to selenium-...@googlegroups.com
Hi, devs,

Resuming all comments:

1) Method Locatable.getCoordinates().getLocationOnScreen() should be renamed to Locatable.getCoordinates().onScreen()
This method should return location of the element relative to the top-left corner of the monitor (screen)
This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
If the element can't be scrolled into view the method should throw an ElementNotVisibleException

2) Method Locatable.getCoordinates().getLocationInViewPort() should be renamed to Locatable.getCoordinates().inViewPort()
This method should return location of the element relative to the top-left corner of  whatever OS-window is being used to display the content. Usually it is the browser window's viewport.
This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
If the element can't be scrolled into view the method should throw an ElementNotVisibleException

3) Method Locatable.getCoordinates().getLocationInDOM() should be renamed to Locatable.getCoordinates().onPage()
This method should return location of the element relative to the top-left corner of the page.
This method should NOT scroll the page and/or frames.

4) Method Locatable.getLocationOnceScrolledIntoView() should be deprecated and removed lately because it is redundant, Locatable.getCoordinates().inViewPort() should be used instead.

5) Method WebElement.getLocation() should delegate down to Locatable.getCoordinates().onPage()

Any additional comments?

Regards,
--
Alexei Barantsev,
Software-Testing.Ru
Selenium2.Ru

Simon Stewart

unread,
Jan 28, 2013, 4:51:23 AM1/28/13
to selenium-...@googlegroups.com
Inline.

On Sun, Jan 27, 2013 at 3:16 PM, Alexei Barantsev <bara...@gmail.com> wrote:
Hi, devs,

Resuming all comments:

1) Method Locatable.getCoordinates().getLocationOnScreen() should be renamed to Locatable.getCoordinates().onScreen()
This method should return location of the element relative to the top-left corner of the monitor (screen)
This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
If the element can't be scrolled into view the method should throw an ElementNotVisibleException

SGTM
 
2) Method Locatable.getCoordinates().getLocationInViewPort() should be renamed to Locatable.getCoordinates().inViewPort()
This method should return location of the element relative to the top-left corner of  whatever OS-window is being used to display the content. Usually it is the browser window's viewport.
This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
If the element can't be scrolled into view the method should throw an ElementNotVisibleException

SGTM. We should add a note that this implementation is designed for users attempting to implement raw native event firing at the OS-level, and that the method isn't generally what users should be using.
 
3) Method Locatable.getCoordinates().getLocationInDOM() should be renamed to Locatable.getCoordinates().onPage()
This method should return location of the element relative to the top-left corner of the page.
This method should NOT scroll the page and/or frames.

Emphasis on the "should" :) Implementations are free to implement this any way that feels sane to them.
 
4) Method Locatable.getLocationOnceScrolledIntoView() should be deprecated and removed lately because it is redundant, Locatable.getCoordinates().inViewPort() should be used instead.

SGTM. 
 
5) Method WebElement.getLocation() should delegate down to Locatable.getCoordinates().onPage()

Perfect.
 
Any additional comments?

None. Thank you!

Simon

Jason Leyba

unread,
Jan 28, 2013, 2:11:14 PM1/28/13
to selenium-...@googlegroups.com
On Mon, Jan 28, 2013 at 1:51 AM, Simon Stewart <simon.m...@gmail.com> wrote:
Inline.

On Sun, Jan 27, 2013 at 3:16 PM, Alexei Barantsev <bara...@gmail.com> wrote:
Hi, devs,

Resuming all comments:

1) Method Locatable.getCoordinates().getLocationOnScreen() should be renamed to Locatable.getCoordinates().onScreen()
This method should return location of the element relative to the top-left corner of the monitor (screen)
This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
If the element can't be scrolled into view the method should throw an ElementNotVisibleException

SGTM
 
2) Method Locatable.getCoordinates().getLocationInViewPort() should be renamed to Locatable.getCoordinates().inViewPort()
This method should return location of the element relative to the top-left corner of  whatever OS-window is being used to display the content. Usually it is the browser window's viewport.
This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
If the element can't be scrolled into view the method should throw an ElementNotVisibleException

SGTM. We should add a note that this implementation is designed for users attempting to implement raw native event firing at the OS-level, and that the method isn't generally what users should be using.

You've got onScreen() and inViewPort() mixed up.  onScreen() is required for OS-level events.  inViewPort() is a stable location that users should use in their tests.

Simon Stewart

unread,
Jan 28, 2013, 6:14:04 PM1/28/13
to selenium-developers


On 28 Jan 2013 19:11, "Jason Leyba" <jml...@gmail.com> wrote:
>
> On Mon, Jan 28, 2013 at 1:51 AM, Simon Stewart <simon.m...@gmail.com> wrote:
>>
>> Inline.
>>
>> On Sun, Jan 27, 2013 at 3:16 PM, Alexei Barantsev <bara...@gmail.com> wrote:
>>>
>>> Hi, devs,
>>>
>>> Resuming all comments:
>>>
>>> 1) Method Locatable.getCoordinates().getLocationOnScreen() should be renamed to Locatable.getCoordinates().onScreen()
>>> This method should return location of the element relative to the top-left corner of the monitor (screen)
>>> This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
>>> If the element can't be scrolled into view the method should throw an ElementNotVisibleException
>>
>>
>> SGTM
>>  
>>>
>>> 2) Method Locatable.getCoordinates().getLocationInViewPort() should be renamed to Locatable.getCoordinates().inViewPort()
>>> This method should return location of the element relative to the top-left corner of  whatever OS-window is being used to display the content. Usually it is the browser window's viewport.
>>> This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
>>> If the element can't be scrolled into view the method should throw an ElementNotVisibleException
>>
>>
>> SGTM. We should add a note that this implementation is designed for users attempting to implement raw native event firing at the OS-level, and that the method isn't generally what users should be using.
>
>
> You've got onScreen() and inViewPort() mixed up.  onScreen() is required for OS-level events.  inViewPort() is a stable location that users should use in their tests.

To be fair, it depends. OnScreen is useful for native events using the awt robot or similar, but os events pumped into the message queue use viewport relative distances.

We might consider renaming viewport as it may not match the DOM view ports. Which is a PITA.

>>> 3) Method Locatable.getCoordinates().getLocationInDOM() should be renamed to Locatable.getCoordinates().onPage()
>>> This method should return location of the element relative to the top-left corner of the page.
>>> This method should NOT scroll the page and/or frames.
>>
>>
>> Emphasis on the "should" :) Implementations are free to implement this any way that feels sane to them.
>>  
>>>
>>> 4) Method Locatable.getLocationOnceScrolledIntoView() should be deprecated and removed lately because it is redundant, Locatable.getCoordinates().inViewPort() should be used instead.
>>
>>
>> SGTM. 
>>  
>>>
>>> 5) Method WebElement.getLocation() should delegate down to Locatable.getCoordinates().onPage()
>>
>>
>> Perfect.
>>  
>>>
>>> Any additional comments?
>>
>>
>> None. Thank you!
>>
>> Simon
>
>

> --
> You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to selenium-develo...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

Simon Stewart

unread,
Jan 28, 2013, 6:15:31 PM1/28/13
to selenium-developers


On 28 Jan 2013 19:11, "Jason Leyba" <jml...@gmail.com> wrote:
>

> On Mon, Jan 28, 2013 at 1:51 AM, Simon Stewart <simon.m...@gmail.com> wrote:
>>
>> Inline.
>>
>> On Sun, Jan 27, 2013 at 3:16 PM, Alexei Barantsev <bara...@gmail.com> wrote:
>>>
>>> Hi, devs,
>>>
>>> Resuming all comments:
>>>
>>> 1) Method Locatable.getCoordinates().getLocationOnScreen() should be renamed to Locatable.getCoordinates().onScreen()
>>> This method should return location of the element relative to the top-left corner of the monitor (screen)
>>> This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
>>> If the element can't be scrolled into view the method should throw an ElementNotVisibleException
>>
>>
>> SGTM
>>  
>>>
>>> 2) Method Locatable.getCoordinates().getLocationInViewPort() should be renamed to Locatable.getCoordinates().inViewPort()
>>> This method should return location of the element relative to the top-left corner of  whatever OS-window is being used to display the content. Usually it is the browser window's viewport.
>>> This method should try to scroll the page and/or frames to make element visible before calculating its coordinates.
>>> If the element can't be scrolled into view the method should throw an ElementNotVisibleException
>>
>>
>> SGTM. We should add a note that this implementation is designed for users attempting to implement raw native event firing at the OS-level, and that the method isn't generally what users should be using.
>
>
> You've got onScreen() and inViewPort() mixed up.  onScreen() is required for OS-level events.  inViewPort() is a stable location that users should use in their tests.

Damn phones and their massive but tiny screens. The stable location that tests should use is onPage.

Simon

>>> 3) Method Locatable.getCoordinates().getLocationInDOM() should be renamed to Locatable.getCoordinates().onPage()
>>> This method should return location of the element relative to the top-left corner of the page.
>>> This method should NOT scroll the page and/or frames.
>>
>>
>> Emphasis on the "should" :) Implementations are free to implement this any way that feels sane to them.
>>  
>>>
>>> 4) Method Locatable.getLocationOnceScrolledIntoView() should be deprecated and removed lately because it is redundant, Locatable.getCoordinates().inViewPort() should be used instead.
>>
>>
>> SGTM. 
>>  
>>>
>>> 5) Method WebElement.getLocation() should delegate down to Locatable.getCoordinates().onPage()
>>
>>
>> Perfect.
>>  
>>>
>>> Any additional comments?
>>
>>
>> None. Thank you!
>>
>> Simon
>
>

Reply all
Reply to author
Forward
0 new messages