# Common JavaScript APIs

Here are some common JS APIs. This is just a partial list. For the full list, see [Test Designer JS Commands Reference](https://docs.appvance.net/Content/AIQ/TechRef/TestDesignerJSCommands/Test_Designer_JS_Commands_Reference.htm).

### \_formSubmit(\_form("formID"))

Form Submit API which can be used instead of Enter Key if the existing page has form in it.

### \_getAttribute(\_byId('table\_name'),"rows")

Used to find the rows in a table and store it in a variable. The following code snippet can beused to validate whether a checkbox is checked or not.

```
var $ch = _getAttribute(_byId('accessor'),"checked");_log($ch)if($ch==false){ _click(_checkbox("accessor")); }else{_assertEqual($ch,"checked"); }
```

### var $msg=\_getText(\_div("custdialog"))

Fetches the text from a dialogue box and stores it in a variable.

- Variants to the above getText are as follows:
- - `<span class="editor-theme-code">getTextSelenium</span>` - Follows the same syntax as above .The difference is it exactly trims the data without having any white spaces.

### var $ch2=eval(\_lastAlert())

Stores the contents of the last pop up into a variable which can later be compared using assertion. If a particular list has a form action, then the following code snippet can be used.

```
_setSelected(_select("accessor ID"),"list Element");_formSubmit(_form("form ID"));
```

### \_mouseOver(\_div("accessor"))

Simulates Mouse Over action.

### \_setFile2(\_byXPath('//\*\[@id="fileBox"\]'),"Test.mp4")

Used for file upload actions/

- - `<span class="editor-theme-code">setFile2</span>` API is similar to setFile API, which uses the same syntax as that of `<span class="editor-theme-code">setFile</span>` API, `<span class="editor-theme-code">setFile2</span>` is used when you want to mimic a user activity where front end validations are involved.
    - While using `<span class="editor-theme-code">setFile2</span>` for file upload make sure you do not give any absolute path or relative path. Example: `<span class="editor-theme-code">_setFile2(_byXPath('//*[@id="fileBox"]'),"Test.mp4");</span>`

### var $length =\_getLength('.tablename tr')

Jquery used to get table length. Its similar to usage in jquery format with selectors except that there we will use ‘.length’. Here its not needed.

- - Example Jquery notation: `<span class="editor-theme-code">$(‘.tableclass tr’).length</span>`
    - Test Designer usage: `<span class="editor-theme-code">getLength(‘.tableclass tr’) (class selector)</span>`  
        Note: Use # if its an id.
    - To find column count too, use : `<span class="editor-theme-code">getLength(‘.tableclass tr td’) or getLength(‘.tableclass tr th’)</span>`

### var $ch=\_getAttribute(\_link("URL Name"),"href")

Gets the HREF URL which can then be stored in a string.

### \_setFile(\_byXPath('//\*\[@id="fileBox"\]'),"{ds}/Test.mp4")

Upload file.

### getComputedStyle(\_div("accessor"),"background-color")

Retrieves background color or any style attribute.

### rteWrite(iframe(“identifier”),”Test in RTE”)

Works inside rich text editor which will always be embedded inside iframe.

### EVAL Usage in Test Designer JS

These can be used if in case no other option is available but to stick with pure jquery usage:

Examples:

```
_eval("ds$('html, body').scrollTop(ds$(document).height())");var data1 = _eval("Math.round(ds$(window).scrollTop())");log(data1);var data2 = _eval("ds$(window).height()");_log(data2);var data4 = +data1 + +data2 ;_log(data4);var data3 = _eval("ds$(document).height()");_log(data3);var end = _eval("Math.round(ds$(window).scrollTop())+ ds$(window).height() == ds$(document).height()");_log(end);if(end == true){_log("scroll bottom is reached");}
```

```
var collection = _eval("ds$('.space-program-detail').not('.hideProgram').find('.program-name')");log(collection.length);
```

```
_log("typeof "+typeof _eval("(function(){})();"));_log( _eval("(function(){return null;})();"));_eval("ds$('html, body').scrollTop(ds$(document).height())");
```