Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Selenium: get coordinates of element

Selenium get coordinates of element

Testing UI can prove to be a quite tricky job when you try to do in automation. In UI testing my experience one essential piece is to know the Coordinates of Element. We’ll try to see how we can use selenium to get coordinates of an element.

Get coordinates of element using javascript
 # @return [Array] of x,y position of element
    def element_position(element)
Get coordinates of element using WebElements properties

WebElements have the properties .size and .location. Both are of type dict.

element = find('locator')


Returns :

{'y': 300, 'x': 278}

Having the location it’s a handy thing but sometimes you might want to know the size of the locator and perform some assertions against that as well.

element = find('locator')


Returns :

{'width': 20, 'height': 30}

For me having this 2 informations , element size and element location I can do a proper UI test is just you need to handle all these information based on the screen resolution you are testing on.

Other useful articles :

How to use : Capybara get attribute

Introducing the Tellurium Selenium Automated Testing Framework

The post Selenium: get coordinates of element appeared first on TestingRepository.

This post first appeared on Testing Repository - Creating Testing, please read the originial post: here

Share the post

Selenium: get coordinates of element


Subscribe to Testing Repository - Creating Testing

Get updates delivered right to your inbox!

Thank you for your subscription