There could be a situation as it happen quite often that default sendKeys option provided by Selenium Webdriver to send text does’t work and even retrieving text doesn’t work too in any of the browser. To handle such a situation, JavascriptExecutor comes to rescue. Therefore, In this article, we are going to learn “How to send and get text using JavascriptExecutor instead of using default ways provided by Selenium Webdriver?”. It’s a super handy solution and works quite every time. 

SendText_JavascriptExecutor_Featured_Image_Techndeck

SEND TEXT AND GET TEXT USING JAVASCRIPTEXECUTOR...!!! Share on X

Example 1. Send text with JavascriptExecutor (Not using Selenium’s sendKeys option)

In this example, we are accessing a website (business.officedepot.com) and entering login name as ‘Techndeck’ using JavascriptExecutor

 

Output:

SendText_JavascriptExecutor_Techndeck

 

Example 2. Get/Retrieve text with JavascriptExecutor

In this example, we are accessing a website (business.officedepot.com) and trying to retrieve the text written on the login button using JavascriptExecutor

 

Output:

 

SEND TEXT AND GET TEXT USING JAVASCRIPTEXECUTOR...!!! Share on X

Do you like this Post? – then check my other helpful posts:

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    http://Techndeck.com deepak.rkgit@gmail.com Verma Deepak