Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Part 1: Usages Of Javascripts In Selenium: Why We Need Javascript Commands In Selenium

Posted on 02/19/2025 By admin

Hello Folks,

We will see series of posts on Usage of JavaScripts in Selenium. Let’s start with basics.

What is JavaScript?

Definition from JS offical website:

“JavaScript (“JS” for short) is a full-fledged dynamic programming language that, when applied to an HTML document, can provide dynamic interactivity on websites.”

I hope you should be aware of basic js. If not, you can refer any online tutorials.

How to execute a js command in any browser manually:

Every browser is js enabled by default which you can disable as well. You can run any js command in a browser. You just need to launch browser console. In console, type any js command and hit enter.

Why we need to execute js commands in Selenium?

Sometimes you will find Selenium commands are not working properly. Below examples are from my working experience on Selenium:

  • Handling nested web elements. I have seen some toggle buttons , check boxes etc which are nested by some other tags like label etc. Normal selenium command “Click” will not be able to click on toggle sometimes, as it will find it is not clickable.
  • Complete area of some web elements like button, checkbox etc are not  clickable. You need to click on specific part of element to perform action. Selenium might fail here some times. In this case also js is very useful.
  • Handling different types of calendar. There are so many types of calendar which are used by developers in different applications. You may need to write separate methods to handle calendar. Here js will solve your problem.
  • Scrolling is also a big problem in selenium. Using js, you can scroll by pixels or to the web element.
  • Handling hidden elements. You can use js to get text or attribute value from hidden web element which can not be done by normal selenium methods.
  • Drag and drop issues can be handled using js.

There are many other occasion where automation testers find js as a better option. Anyways using javascript commands should be last resort if normal selenium commands are not working.

Next post onward, we will see frequently used js commands in selenium. Stay tuned.

If you have any doubt, feel free to comment below. If you like my posts, please like, comment, share and subscribe. #ThanksForReading

#HappySelenium

Uncategorized

Post navigation

Previous Post: REST Assured Tutorial 24 – Creating JSON Array Request Body Using List
Next Post: Postman Tutorial Part 30-Extracting and Asserting Request & Response Headers in Postman

Related Posts

REST Assured Tutorial 31 – How To Create POJO Classes Of A Nested JSON Payload Uncategorized
getOrDefault() – A Method Of Map Interface In Java Uncategorized
IMG_4440 – Make Selenium Easy Uncategorized
July 7, 2018 – Make Selenium Easy Uncategorized
April 15, 2017 – Make Selenium Easy Uncategorized
dataprovider 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