How to click on (X, Y) coordinates using JavascriptExecutor in Selenium?

Category: Selenium WebDriver 14 0

Many a time, we face an issue and we get an error message similar as- “Element is not clickable at point (X, Y)” So to solve such issues we have various techniques available in Selenium and Java, including which we are going to discuss today. We will discuss other techniques too in coming days, but let’s focus today on clicking on some XY coordinates using JavascriptExecutor in Selenium WebDriver.

This week we are only focussing on JavascriptExecutor tutorials in Selenium WebDriver. This is the last exclusive tutorial on JavascriptExecutor command; further, we will have a single powerful tutorial on JavscriptExecutor which will have the compilation of all the exclusive posts along with some additional commands which will be helpful to you achieving another milestone in your Selenium learning journey.

Don’t Miss:

How to send texts and retrieve texts using JavaScript?

Why element fails at certain coordinates, despite having right XPath?

Did you ever think why it fails even if we provided the right XPath to the element?

Let me tell you based on my analysis…

  • The testable browser has the older version
  • You are using outdated WebDriver, like ChromeDriver, GeckoDriver, etc
  • Element is disabled
  • By default, WebDriver clicks in the middle of the Web element, that is not active
  • Elements are not properly synced (Suggestions: Fluent wait works well for the Synchronization)

These could be the immediate reasons for the failure on click at certain coordinates.

If you have checked and corrected the above factors of failure then I expect that it will work well. If you haven’t done yet then I recommend you to get X & Y coordinates and click on each coordinates using JavascriptExecutor.

We don’t have any other choice, except, getting the coordinates and triggering the click operation on those specific web elements at particular (X, Y) coordinates using JavascriptExecutor.

click coordinates using javascriptexecutor

Let’s begin the game….

Click on (X, Y) coordinates using JavascriptExecutor in Selenium WebDriver

I recommend you to update your browser first then try to separately click at X and Y coordinates using JavascriptExecutor.

Click on X coordinates using JavascriptExecutor, while keeping Y coordinates constant

Here is the command to click at X coordinates while keeping the Y coordinate constant.

Here is the complete program:

Explanations

WebDriver scrolls down till it reaches the X coordinates and then clicks.

Click on Y coordinates using JavascriptExecutor, while keeping X coordinates constant

 

Here is the complete program.

Explanations

WebDriver scrolls till it reaches theY coordinates and then clicks.

This is all about clicking at (X, Y) coordinates using JavascriptExecutor in Selenium WebDriver. There are many ways to click on particular coordinates. Stay connected so that you can read those tutorials too. If you find any doubts, or, if you have some suggestions to make this portal better, then feel free to reach to me via comment, contact page, and social media.

This is Avinash Mishra, signing off!

Related Articles

Add Comment