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...!!! Click To Tweet

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...!!! Click To Tweet

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

Other Useful References: