JavascriptExecutor in WebdriverIO

JavaScript is the preferred language inside the browser to interact with HTML dom. This means that a Browser has JavaScript implementation in it and understands the JavaScript commands. You can disable it using browser options in your browser.

The javascript, we use to write the out webdriverio scripts same as the javascript used in the browser.

The first thing to know that the JavaScriptExecutor comes separately and also comes under the WebDriver (not webdriverIO) but both do the same thing. Within the WebDriverIO, javascript executor is bundled and it is named as executeScript.

Javascript executed in browser is same for all selenium technologies because it is dependent on browser not on Program which executes it.

We can do anything and everything a developer does use javascript inside an HTML browser. Below you will find the example.

browser.executeScript("javascript or Jquery")

How to enter a value into the textbox:

browser.executeScript("document.getElementById('email').value='[email protected]'")

How to click a button


How to refresh a window


How to get the text of a particular web element

var text = js.executeScript("return document.getElementById('btn2').innerHTML").toString();
console.log("WebElement Text is : "+ text);

How to get the title of the WebPage:

browser.executeScript("return document.title")

How to scroll vertically for certain pixels, below code vertically scrolls 500 pixels towards down.


How to scroll till the bottom of the web page:

browser.executeScript("window.scrollTo(0, document.body.scrollHeight)")

How to scroll to a particular element:


How to navigate back to the page


How to navigate to the next page:


This way we can JavaScript Executor to perform certain actions on a webpage if the normal selenium webdriver methods are not working.

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
  • could u pls post on how jquery is active like === 0 
  • HarshavardhanReddy I is not working. Please resume.
  • hhhhhhhh
  • Reply
  • dfsdfsdf
  • Kumar Saurabh
  • Reply
  • Reply