Menu Next Topic
In our previous posts, we covered topics on selenium frames, tables, forms, waits and text fields. Now, we will take a look at page scrolling.
A lot of times, I often hear testers complain that they tried to click on a link or a button during their tests and they couldn’t. In most situations, they get error messages like this “Element is not clickable at point (511, 17.5). Other element would receive the click:“.
To prevent us from having such issues we will take a look at the getLocation() method which selenium provides to solve this challenge. The getLocation() method is used to find a point, containing the location of the top left-hand corner of an element. This method contains the X,Y coordinate of any element on a webpage. For example, in the error message above you will notice that it says “Element is not clickable at point (511, 17.5)”. These are the coordinates for a particular element that selenium was trying to click on, but couldn’t. Therefore, in such scenarios, we need to get the X, Y coordinates of that element then tell selenium to scroll down or up based on those coordinates. We can do this, by chaining the getLocation() method with the getY() method or getX() method.
Without further ado, let’s follow the steps below and then dive into our code to understand how we test/implement a page scroll.
- Navigate to the sample test page.
- Scroll down to the “Open page in the same window” link
- Click on the link
In conclusion, we have looked at how to scroll up or down a webpage to click on a particular element. This approach can be used in your future tests. You can download or clone this test from the Testdiary Github.
Click: Page Scroll
Menu Next Topic