Resources

Knowledge Base

Inject Javascript Code Into A WebPage

Task

This sample will show you how to inject Javascript code into a web page in order to get the errors from wrong completed Input fields.

Steps to automate

  1. Open http://www.uipath.com/download-free-automation-software-trial.
  2. Type wrong data into the First Name, Email and Phone Number input fields.
  3. Click "Request Free Trial".
  4. Collect the error messages regarding the invalid input fields using Javascript code.

Solution

  1. Use "Open Browser" activity and specify the above URL.
  2. Use "Type Into" activities for each of the First Name, Email and Phone Number fields and write invalid inputs.
  3. With a "Click" activity, select the "Request Free Trial" button.
  4. Now it's time to execute our Javascript code. This will run on the HTML document in the "Open Browser" context. You can write your code into a file with .js extension and put that into the "ScriptCode" property of the "Inject js script" activity. Also, you have to create a variable and set it into the "ScriptOutput" property.
  5. Use a "Message box" activity to display the variable that stores the result returned by the Javascript code.

 

Inject Javascript Code Into A WebPage