Inject JavaScript into the Web Page

Inject a JavaScript function into a web page.

Command availability: IBM RPA SaaS and IBM RPA on premises

Script syntax

IBM RPA's proprietary scripting language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

webInjectJavaScript --script(String) (Boolean)=value

Dependencies

Use the Start Browser (webStart) command to start a browser or use the Find Internet Explorer Browser (findBrowser) command to attach the Microsoft Internet Explorer before using the Inject JavaScript into the Web Page (webInjectJavaScript) command.

Input parameter

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Java Script script Required Text JavaScript function to inject into the page.

Output parameter

Designer mode label Script mode name Accepted variable types Description
Success value Boolean Returns true when injecting the JavaScript code successfully, otherwise returns false.

Example

Use Inject JavaScript into the Web Page (webInjectJavaScript) command to change the background color.

webStart --name browser --type "Chrome"
webNavigate --url "www.example.com"
webInjectJavaScript --script "document.body.style.background = \"blue\";" success=value
webClose --name browser --leavebrowseropen

Limitations

This command does not parse JavaScript function, nor it identifies if the code ran successfully.