How to pass value as a variable for anchor tag index in a javascript function


Hi, @alekhya, sorry for the late response. Passing the variable involves some quoting and concatenation in the javascript function.

You can examine the snippet below for one way to pass a variable into a JS function. There are a number of others, you can check many of the posts on the forum.

WebAutomation.ExecuteJavascript BrowserInstance:  Browser  \
                                function ExecuteScript() { 
                                m = document.querySelectorAll('input[ng-reflect-name*="mail"]');
                                m[0].value = '""" + emailList[0] + """';

As you can see, the first part of the function is passed as an entire triple-quoted string, concatenated with a variable (such as your anchor index tag), then concatenated with another triple-quoted string to finish up the function. There a number of other ways to quote, as you can use single quotes, double quotes, triple quotes, and the back-tick character (very difficult to enter into the forum posts :grinning:): `


1 Like