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

2020-08-13T18:30:00Z

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  \
                                Javascript:"""
                                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:): `

Regards,
burque505

1 Like