Skip to content

runScript command - Article

Article_runScript_Command:

Article Title:

To perform DOM level action in the test execution

Article Section: Before you read this you may want to see

https://eureqa.uservoice.com/knowledgebase/articles/1115380-runscript-ui-automation-manipulation

Article Section: Main Article

The purpose of this topic to perform javascript level action like select, click on any element in the application by providing the unique id to the element.

How to get the element id from DOM level?

  • Open the application URL
  • Inspect the element by right-clicking or Press F12, for the element on which you want to perform click action.


  • Get the element id from the DOM and use in the element id in the javascript as mentioned in the below example. 
  • If the UI elements do not have a unique id in any application, you can provide a temporary id of your choice using the command the assignId and use that id in the XPath or you can go with any other attribute of that element for example, "class", "name" etc instead of id in the XPath. The assigned unique id can be used in runScript command to perform the click action.

Command Examples for Reference:

In this example, an application is launched using the open command and waitForVisible command is used in order to wait for the page to be loaded. Once the page is loaded, the accessibility of the sign in account link is enabled and we need to click on Sign In account link by using the runScript command.

Solution 1:

# Command   Target Value
Launch Application
1 open   https://www.amazon.in  
Wait until the page loads and the text which is given in the value field is displayed in the screen
2 waitForVisible   //div[@id="nav-logo"]  
To perform click action on Sign In account link in home page
3 runScript   document.getElementById('nav-link-accountList').click();  

Solution 2:

# Command   Target Value
Launch Application
1 open   https://www.amazon.in  
Wait until the page loads and the text which is given in the value field is displayed in the screen
2 waitForVisible   //div[@id="nav-logo"]  
To assign a unique id for the select dropdown Xpath  
3 assignId   //select[@aria-describedby="searchDropdownDescription"] select_dropdown
To perform click action on Sign In account link in home page
3 runScript   document.getElementById('select_dropdown').value='search-alias=electronics';  


Tips, Tricks, Gotchas & Best Practices:  

  • The runScript command can also be used if the select command fails to perform the select action like select by index or select by value options in the dropdown. Syntax to select the value from the dropdown is provided in Solution 2.

Representative Usage Scenarios for this Example:

Scenario 1:

Consider application forms where you need to select a value from the drop-down or you need to perform click action to an element. We can perform these actions using javascript providing in the runScript command. The syntax used in Solution 1 is for click action and Solution 2 is for selecting a drop down value on an element in the application.

Article Section: After reading this you may want to see:

https://eureqa.uservoice.com/knowledgebase/articles/1115554-assignid-ui-automation-manipulation

Feedback and Knowledge Base