Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Selenium Interview Question 8 – What is Difference between WebDriver click and JavaScript click methods

Posted on 02/19/2025 By admin

In this post we will see another frequently asked interview question:-

Difference between WebDriver click() and JavaScript click() method in Selenium.

We can perform click on a web element of a web page in two ways:-

  1. Using WebDriver click – element.click()
  2. Using JavaScript click –((JavascriptExecutor)driver).executeScript(“arguments[0].click()”, element); ( Note- driver is a WebDriver instance.)

So question must be arised in your mind, which is better and when to use.

Since Selenium 3, maximum browser are providing their respective browser driver which implements WebDriver API. Selenium communicates to these browser drivers through HTTP commands and these drivers communicates natively with browser. Official documentation of Selenium says:-

“Selenium-WebDriver makes direct calls to the browser using each browser’s native support for automation. “

So we can say that the way chrome browser allows a click on a web element may be different from other browsers.

So when we click on a webelement using Selenium WebDriver , it checks two preconditions before clicking:-

  1. The element must be visible.
  2. It must have a height and width greater than 0.

If preconditions are not satisfied, you will get exceptions stating element is not clickable or interactable. Refer click() method in official document here.

But in JavaScript clicks does not check these preconditions before clicking. The HTMLElement.click() method simulates a mouse click on an element. When click() is used with supported elements (such as an ), it fires the element’s click event. Reference here.

So, JavaScript could click on a web element which may not be clickable by WebDriver API. So use WebDriver click as much as possible and go for JavaScript click when WebDriver click does not work.

WebDriver APIs are designed to simulate the actions which a real user will perform on front end of application. When we go for JavaScript, this is not taking into consideration. JavaScript ways may not catch the bugs which is main goal of automation scripting.

JavaScript operations may not call actions sometimes. Suppose when you click on a button, some popup should appear. That can be relate as onClick event. You may encounter these issues. These issues will not come if you use WebDriver APIs.

I would like to share a problem I faced while automating. There was a Date of birth field which takes input from user and calculates actual age. I typed DOB using Javascript way and it was not calculating actual age and event set on DOB field was not called.

If you like above post and feel it is worth to share to reach it to maximum people, please do.

#ThanksForReading

Uncategorized

Post navigation

Previous Post: TestNG Tutorials 7: How To Create Customized TestNG XML?
Next Post: Git Tutorial 3 – Install GIT On Windows – Step By Step

Related Posts

July 2018 – Make Selenium Easy Uncategorized
Git Tutorial 4 – Create a new Git repository – git init Command Uncategorized
APIGoRest – Make Selenium Easy Uncategorized
api Uncategorized
image – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark