- WebdriverIO Tutorial
- WebdriverIO - Home
- WebdriverIO - Introduction
- WebdriverIO - Prerequisite
- WebdriverIO - Architecture
- WebdriverIO - Getting Started with NodeJS
- WebdriverIO - Installation of NPM
- WebdriverIO - VS Code Installation
- WebdriverIO - Package.json
- WebdriverIO - Mocha Installation
- Selenium Standalone Server Installation
- WebdriverIO - Configuration File generation
- WebdriverIO - VS Code Intellisense
- WebdriverIO - Wdio.conf.js file
- WebdriverIO - Xpath Locator
- WebdriverIO - CSS Locator
- WebdriverIO - Link Text Locator
- WebdriverIO - ID Locator
- WebdriverIO - Tag Name Locator
- WebdriverIO - Class Name Locator
- WebdriverIO - Name Locator
- Expect Statement for Assertions
- WebdriverIO - Happy Path Flow
- WebdriverIO - General Browser Commands
- WebdriverIO - Handling Browser Size
- WebdriverIO - Browser Navigation Commands
- Handling Checkboxes & Dropdowns
- WebdriverIO - Mouse Operations
- Handling Child Windows/Pop ups
- WebdriverIO - Hidden Elements
- WebdriverIO - Frames
- WebdriverIO - Drag & Drop
- WebdriverIO - Double Click
- WebdriverIO - Cookies
- WebdriverIO - Handling Radio Buttons
- Chai Assertions on webelements
- WebdriverIO - Multiple Windows/Tabs
- WebdriverIO - Scrolling Operations
- WebdriverIO - Alerts
- WebdriverIO - Debugging Code
- WebdriverIO - Capturing Screenshots
- WebdriverIO - JavaScript Executor
- WebdriverIO - Waits
- WebdriverIO - Running Tests in Parallel
- WebdriverIO - Data Driven Testing
- Running Tests from command-line parameters
- Execute Tests with Mocha Options
- Generate HTML reports from Allure
- WebdriverIO Useful Resources
- WebdriverIO - Quick Guide
- WebdriverIO - Useful Resources
- WebdriverIO - Discussion
WebdriverIO - JavaScript Executor
Inside the WebdriverIO, the JavaScript Executor is bundled and called executeScript. The JavaScript Executor is capable of performing all the tasks on a page whenever normal WebdriverIO methods are not working as expected.
Syntax
The syntax for the JavaScript executor is as follows −
browser.executeScript("JavaScript command")
Actions with JavaScript Executor
Some actions performed with JavaScript Executor are as follows −
To enter a text - AB into an edit box having id as txt, use the command given below −
browser.executeScript("document.getElementById('txt').value='AB'")
To click a link, use the command given below −
browser.executeScript("document.querySelector('.lnk').click()")
The command given below is used for refreshing windows −
browser.executeScript("history.go(0)") var t = js.executeScript("return document.getElementById('bln').innerHTML").toString()
The command to scroll down a page by 350 pixels is as follows −
browser.executeScript("window.scrollBy(0,350)") browser.executeScript("window.scrollTo(0, document.body.scrollHeight)")
The command given below is used to scroll down upto an element having class as tcl.
browser.executeScript("document.querySelector('.tcl').scrollIntoView()") browser.executeScript("window.history.back()")
Following command is used to go forward in browser history −
browser.executeScript("window.history.forward()") browser.executeScript("return document.title")
Advertisements