Help Docs

Advanced web script editing in Web Transaction(Browser) monitor

The Web Transaction (Browser) monitor records and saves the user actions in a web script. These powerful scripts act as a means to measure the web performance via a real browser simulation. The scripts describe actions like mouse clicks, validations, navigation and more. You can update the existing web script actions using our inline client web script editor. This advanced web scripting tool lets you manipulate your recorded actions and update your Web Transaction (Browser) Monitor configuration without having to rerecord the transaction using a recorder. By default,  the Web Transaction (Browser) uses a feature called Intelligent Playback to identify the attribute level changes of the HTML element; and auto updates your recorded scripts. However, if you want to stop intelligent playback, enter and execute command update_intelligent_play_candidates("false") in your advanced web script editor.

Following are the various commands that are used to update the web script. Please pay attention to the format in which these expressions are updated in the editor.

Note
  • Every parameter in a command is mandatory. However, for the parameter DISPLAY_NAME, you can pass an empty value between double quotes while maintaining the defined format for each command.
  • If you are attempting to perform a click that would initiate a download, you will see a pop-up "File download is not supported". Please note that the web transaction monitor does not support a file download action and you will need to close the pop-up box to proceed.

Web Script Commands

1. Create a step.

Command:begin_step("<STEP_NAME>","<STEP_URL>")

Example:
begin_step("Step 1: Loading http://www.vtitan.com","http://www.vtitan.com")
begin_step("Step 2: Click CORPORATE","http://www.vtitan.com/corporate.html").

 
Note

If the attribute Ignore the step status is set to true, then you'll be able to proceed to the next step even if the current step fails. The transaction can move to the next step only if the error does not affect the progress of the transaction. If it is false, the transaction process will be stopped when the step fails. For example:

begin_step("Step 1: Loading http://www.vtitan.com", "http://www.vtitan.com", "true")
begin_step("Step 2: Loading http://www.vtitan.com", "http://www.vtitan.com", "false")

 

2. Open a web page.

Command:load_page("<OPEN_URL>")

Example:
load_page("https://www.vtitan.com/coporate.html")

 
Note

OPEN_URL = Base_URL to start a transaction

3. Wait for the page to load until you receive HTTP status code 200.

Command: wait_for_page_to_load()
Note

This has to be included after every action (i.e., which involves URL change)

4. Verify the page status.

Command: verify_page_load_status()
Note

This has to be included after every action (i.e., which involves URL change)

This command helps you to verify whether the page has loaded or not using the status code.

5. Specify authentication credentials.

Command: set_auth_credentials("<DOMAIN>","<USER_NAME>","<PASSWORD>")

Example:
set_auth_credentials("vtitan.com","xyz","123")
Note

 

  • DISPLAY_NAME for internal use
  • INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter
  • Syntax:

    #SEP#id=<ELEMENT_ID>#SEP#name=<ELEMENT_NAME>#SEP#linktext=<ELEMENT_LINKTEXT>#SEP#css=<ELEMENT_CSS>#xpath=<ELEMENT_XPATH_1>#XPATH#<ELEMENT_XPATH_2>#XPATH#<ELEMENT_XPATH_3>#XPATH##SEP#

 

6. Click on an element.

Command: click_element_by_id/name/linktext/css/xpath("<ELEMENT_ID/NAME/LINKTEXT/CSS/XPATH>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")

Example:
click_element_by_id("corporate","disp_corp","#SEP#id=corporate#SEP#name=corporate#SEP#linktext=CORPORATE#SEP
#css=#topmenu>li>a#SEP#xpath=//a[contains(text(),'CORPORATE')]#XPATH#//ul[@id='topmenus']/li/a#XPATH#
//a[contains(@href, 'corporate.html')]#XPATH#//tr[2]/td/ul/li/a#XPATH##SEP#")
Note

 

  • ELEMENT_ID should be given as the first parameter in case of click_element_by_id, ELEMENT_NAME in case of click_element_by_name and respectively for other properties.
  • INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter

 

7. Double click on an element.

Command: double_click_by_id/name/linktext/css/xpath("<ELEMENT_ID/NAME/LINKTEXT/CSS/XPATH>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")

Example:
double_click_by_id("corporate","disp_corp","#SEP#id=corporate#SEP#name=corporate#SEP#linktext=CORPORATE#SEP
#css=#topmenu>li>a#SEP#xpath=//a[contains(text(),'CORPORATE')]#XPATH#//ul[@id='topmenus']/li/a#XPATH#//a[contains
(@href, 'corporate.html')]#XPATH#//tr[2]/td/ul/li/a#XPATH##SEP#")
Note

 

  • ELEMENT_ID should be given as first parameter in case of double_click_by_id, ELEMENT_NAME in case of double_click_by_name and respectively for other properties.
  • INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter

 

8. Mouseover an element.

Command: mouse_over_by_id/name/linktext/css/xpath("<ELEMENT_ID/NAME/LINKTEXT/CSS/XPATH>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")

Example:
mouse_over_by_id("corporate","disp_corp","#SEP#id=corporate#SEP#name=corporate#SEP#linktext=CORPORATE#SEP#
css=#topmenu>li>a#SEP#xpath=//a[contains(text(),'CORPORATE')]#XPATH#//ul[@id='topmenus']/li/a#XPATH#
//a[contains(@href, 'corporate.html')]#XPATH#//tr[2]/td/ul/li/a#XPATH##SEP#")
Note

 

  • ELEMENT_ID should be given as the first parameter in case of mouse_over_by_id, ELEMENT_NAME in case of mouse_over_by_name and respectively for other properties. Both click element and mouseover takes the same parameters; only the function name changes.
  • INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter

 

9. Enter value inside an input field.

Command: set_text_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<TEXT_VALUE>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")

Example:
set_text_by_id("username","xyzuser","disp_username,"#SEP#id=username#SEP#name=username#SEP#css=
#topmenu>li>input[1]#SEP#xpath=//ul[@id='topmenus']/li/input[1]#XPATH#//input[1]#XPATH
#//tr[2]/td/ul/li/input[1]#XPATH##SEP#")
Note

 

  • ELEMENT_ID should be given as the first parameter in case of set_text_by_id, ELEMENT_NAME in case of set_text_by_name and respectively for other properties.
  • TEXT_VALUE - value to be entered in the text field
  • INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter

 

10. Enter value inside an input field.

Command: type_keys_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<TEXT_VALUE>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")

Example:
type_keys_by_id("username","xyzuser","disp_username,"#SEP#id=username#SEP#name=username#SEP#css=#
topmenu>li>input[1]#SEP#xpath=//ul[@id='topmenus']/li/input[1]#XPATH#//input[1]#XPATH
#//tr[2]/td/ul/li/input[1]#XPATH##SEP#")
Note

 

  • ELEMENT_ID should be given as the first parameter in case of type_keys_by_id, ELEMENT_NAME in case of type_keys_by_name and respectively for other properties.
  • TEXT_VALUE - the value that needs to be entered in text field
  • INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter

 

11. Add password.

Command: set_password_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<PASSWORD>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")

Example:
set_password_by_id(password,"123password","disp_password,"#SEP#id=password#SEP#name=password#SEP
#css=#topmenu>li>input[2]#SEP#xpath=//ul[@id='topmenus']/li/input[2]#XPATH#//input[2]#XPATH
#//tr[2]/td/ul/li/input[2]#XPATH##SEP#")
Note

 

  • ELEMENT_ID should be given as the first parameter in case of click_element_by_id, ELEMENT_NAME in case of click_element_by_name and respectively for other properties.
  • Password - the password that needs to be entered in the password field
  • INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter

 

12. Select an entry from select menu.

a) Select by innerHTML.

Command: select_text_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<TEXT>","<DISPLAY_NAME>","<"INTELLIGENT_PLAY_CANDIDATES">)

Example:
select_text_by_id("state","california","disp_state","#SEP#id=id_state#SEP#name=name_state#SEP#css=#topmenu>li>select[3]
#SEP#xpath=//ul[@id='topmenus']/li/select[3]#XPATH#//select[3]#XPATH#//li/select[3]#XPATH##SEP#
Note

INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter

b) Select by value.

Command: select_value_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<VALUE>","<DISPLAY_NAME>","<"INTELLIGENT_PLAY_CANDIDATES">)

Example:
select_value_by_id("state","California-US","disp_state","#SEP#id=id_state#SEP#name=name_state#SEP#css=#topmenu>li>select[3]#SEP
#xpath=//ul[@id='topmenus']/li/select[3]#XPATH#//select[3]#XPATH#//li/select[3]#XPATH##SEP#
Note

INTELLIGENT_PLAY_CANDIDATES - INTELLIGENT_PLAY_CANDIDATES contains identifiers of an element and can be used to access a particular element. If an identifier fails, the element can still be accessed using the remaining available identifiers. Different types of element identifiers should be separated by the #SEP# delimiter and different XPath's should be separated by the #XPATH# delimiter

c) Select by index. 

Command: select_index_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<INDEX>","<DISPLAY_NAME>","<"INTELLIGENT_PLAY_CANDIDATES">)

Example:
select_index_by_id("state","3","disp_state","#SEP#id=id_state#SEP#name=name_state#SEP#css=#topmenu>li>select[3]
#SEP#xpath=//ul[@id='topmenus']/li/select[3]#XPATH#//select[3]#XPATH#//li/select[3]#XPATH##SEP#
Note

index starts from 0.

13. Uncheck the check box.

Command: clear_selection_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<DISPLAY_NAME>")

Example:
clear_selection_by_id("cartype","disp_name")

14. Select the check box.

Command: check_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH">,"<DISPLAY_NAME>","<INTELLEGENT_PLAY_CANDIDATES>")

Example:
check_by_id("volvo","car_type","#SEP#id=volvo#SEP#name=volvo#SEP#css=#topmenu>li>input[1]#SEP
#xpath=//ul[@id='topmenus']/li/input[1]#XPATH#//input[1]#XPATH#//tr[2]/td/ul/li/input[1]#XPATH##SEP#

15. Unselect the check box.

Command: uncheck_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH">,"<DISPLAY_NAME>","<INTELLEGENT_PLAY_CANDIDATES>")

Example:
uncheck_by_id("volvo","car_type","#SEP#id=volvo#SEP#name=volvo#SEP#css=#topmenu>li>input[1]
#SEP#xpath=//ul[@id='topmenus']/li/input[1]#XPATH#//input[1]#XPATH#//tr[2]/td/ul/li/input[1]#XPATH##SEP#

16. Select a frame before performing an action.

Command: 
select_frame_by_id/name/index/src("<FRAME_ID/NAME/INDEX/SRC>")
select_frame("relative=up") - for moving back to top frame from the specific frame.

Example:
select_frame_by_id("topframe")
Note

use select_frame("relative=up") after performing any action inside child frame

17. Select a parent window.

Command:
selectMainWindow()

18. Select a window before performing any action.

Command: select_window_by_name/title/index("<WINDOW_NAME/TITLE/INDEX>")

Example:
select_window_by_name("contentWindow")

19. Close the window.

Command: 
close_window_by_name/title/index("<WINDOW_NAME/TITLE/INDEX>")
close_window() - closes the last selected window

Example:
close_window_by_name("contentWindow")
Note

WINDOW_NAME/TITLE/INDEX used here will be the one that you'd have used in select_window.

20. Pause for a specific time.

Command: wait("<TIME_IN_MILLISECONDS>")

Example:
wait("5000")
Note

Time should be specified in milliseconds.

21. Verify the presence of text on a webpage

Command: assert_text_present("\"<TEXT_1>\" \"<TEXT_2>\"", "true")

Example:
assert_text_present("CORPORATE","true")
assert_text_present("\"CORPORATE\"  \"PRODUCTS\"","true")
Note

For verifying presence of multiple text in a webpage, specify each text in double quotes and escape double quotes (\"CORPORATE\"). If you've specified it as "true," the playback of transaction steps would not stop even during a failure. However, if you've specified it as "false", the playback would stop as and when the failure gets reported.

22. Verify the absence of text on a web page

Command: assert_text_not_present("\"<TEXT_1>\" \"<TEXT_2>\"", "true")

Example:
assert_text_not_present("error","true")
assert_text_not_present("\"error\"  \"warning\"","true")
Note

For verifying absence of multiple text in a webpage, specify each text in double quotes and escape double quotes (\"error\"). If you've specified it as "true," the playback of transaction steps would not stop even during a failure. However, if you've specified it as "false", the playback would stop as and when the failure gets reported.

23. Check the title of the current web page

Command: assert_title("<TITLE>")

Example:
assert_title("vTitan | Safer Health for everyone")

24. Specify confirmation of alert box

Command: assert_confirmation("<ALERT_BOX_MESSAGE>")

Example:
assert_confirmation("Do you want to log out?")

25. Confirm alert box

Command: assert_alert("<ALERT_BOX_MESSAGE>")

Example:
assert_alert("Do you want to log out?")

26. Get the text to be used in the prompt box

Command: answer_on_next_prompt("<PROMPT_TEXT>")

Example:
answer_on_next_prompt("XYZ")

27. Check the prompt message

Command: assert_prompt("<PROMPT_MESSAGE">)

Example:
assert_prompt("Please enter your name")

28. Ignore modal dialogue

Command: ignore_modal_dialog("true")

29. Verify your URL

Command: assert_location("<URL>","true")

Example:
assert_location("http://vtitan.com/corporate.html","true")
Note

For verifying the current URL loaded, specify it in double quotes(\"URL\"). If you've specified it as "true," the playback of transaction steps would not stop even during a failure. However, if you've specified it as "false", the playback would stop as and when the failure gets reported.

Command: assert_location("URL","BOOLEAN","BOOLEAN")
Example: assert_location("http://zylker.com/corporate","true","true")
Note

For verifying the current URL, specify it in double quotes(\"URL\"). If you've specified it as "true" in the second parameter, the playback of transaction steps would not stop even during a failure. However, if you've specified it as "false", the playback would stop as and when the failure gets reported. If the last parameter is true, it will check whether content is present inside the loaded current URL. If it’s false, it will check the exact content with the loaded URL.

30.Wait for an element to load

Command: wait_for_element_presence("identifier","identifier_value",timeout)


Example:

wait_for_element_presence("id","country_code","40")

 
 
 

The wait_for_element_visibility function waits for the element to become visible before interacting with it. This approach helps to prevent errors that might occur if your script tries to interact with an element that is not yet visible to the user.

 

31.Wait for a page to load

Command: set_page_load_timeout("45")

Note:This will add an extra wait time of 15 seconds over the default value.

Note

Example: Check the status of Vtitan.com
Step 1:
Load the url (http://www.vtitan.com)
Check for the keyword not present "error"

Step 2:
Click on CORPORATE
Check for the keyword "PRODUCTS"

 

32. Open a new URL of the same domain

Example: navigate_to("www.vtitan.com/products.html")

Note:This will open the page vtitan.com/products without performing any click action.

33. Verify the presence of an element keyword on the webpage

Command: assert_element_keyword_check("identifier","identifier_value","value" )

Note: The identifier could be anything such as an id, name, css or xpath.

Example: assert_element_keyword_check("id","state","California")

34. Verify the presence of an element  on the webpage

Command: assert_element_check("identifier","identifier_value")

Note: The identifier could be anything such as an id, name, css or xpath.

Example: assert_element_check("id","state")
One of the challenges of automated testing is to ensure that the test scripts can interact with the web elements reliably and consistently. Sometimes, the details may not be immediately available due to various factors, such as dynamic content or slow network speed. Waiting for element presence can improve the test scripts' robustness and reliability in such cases. This technique is beneficial for single-page applications that use frameworks like Angular, Vue, React, etc., as they often update the web page without reloading it.

Waiting for element presence can improve the test scripts' robustness and reliability in such cases. This technique is beneficial for single-page applications that use frameworks like Angular, Vue, React, etc., as they often update the web page without reloading it.

35. Wait for an element to be visible

Note: This may not work for AJAX calls.
Command: wait_for_element_visibility("identifier","identifier_value",timeout)

Example: wait_for_element_visibility("id","country_code","40")
Note

When the content/links change or are dynamic, you should use static xpath (Position based xpath). Site24x7 captures xpaths too, but we have to remove other attributes and keep the Position based xpath alone.

Action with dynamic identifiers :

click_element_by_id("az1234","disp_corp","#SEP#id=az1234#SEP#name=az1235#SEP##SEP#linktext=test123
#SEP#xpath=//a[contains(text(),'test123')]#XPATH#xpath=//ul [@id='topmenus1234']/li/a#XPATH#//a
[contains(@href,'tesing123.html')] #XPATH#//tr[2]/td/ul/li/a#XPATH##SEP#")

After removing the dynamic identifier and the action with the position based xpath this is what you'll obtain :
click_element_by_xpath("//tr[2]/td/ul/li/a","disp_corp","#SEP#xpath=//tr[2]/td/ul/li/a#XPATH##SEP#")

Also, in some cases if it is not possible to obtain the static position based xpaths while recording, then you can create it manually.

In test automation, verifying the page load status is essential to avoid issues that might occur if your script tries to interact with elements on a page that hasn't fully loaded. Waiting for the page to load completely helps to prevent errors caused by elements that are not available due to asynchronous behavior, slow network connections, or dynamic content loading.

 

36. Uploading a test file

Command:  upload_file("identifier","identifier_value"","file_type","display_name”)

Note: The Identifier value could be ID/NAME/LINKTEXT/CSS/XPATH and supported file_type's are txt/jpg/png/zip/json/csv/xml.

Example: upload_file("id","state","jpg","display_name")

37. If Condition

Syntax:  
if(conditionalMethod(arguments)): - commands - elseif(conditionalMethod(arguments)): - commands - else(): - commands - endif():

Conditional Methods could either be "true" or "false", meaning conditionalMethod(arguments) will obtain the reply as true/false.

Commands such as click_element and assertText can be used. We can provide multiple commands in a block.

  • if(true), the commands below "if" will get executed and it skips "else if" & "else".

  • if(false), the commands below "if" will get skipped and the next conditions (say "else if") will be considered and if "else if" condition fails, it will move to the next "else if", if it is available or moves to the next "else" condition.

if(conditionalMethod()): or elseif(conditionalMethod())):

if you want to know the availability of an element, you can proceed with the is_element_available method.

Example:
is_element_available("element_by_id/name/linktext/css/xpath", "<ELEMENT_ID/NAME/LINKTEXT/CSS/XPATH>") ===> 2 arguments

Example:

if(is_element_available("xpath","//a[contains(text(),CLOSE)]")):

if you want to know the availability of a word on the current webpage, you can use the is_content_available method is_content_available("any word that is present in the webpage") ===> 1 argument 

Example:

if(is_content_available("CLOSE")):

if you want to check whether the element contains a particular word, you can make use of the below is_elementwithcontent_available method

Example:
is_elementwithcontent_available("element_by_id/name/linktext/css/xpath" , "<ELEMENT_ID/NAME/LINKTEXT/CSS/XPATH>" , ") ===> 3 arguments

  • First argument - type of the identifier
  • Second argument- value of the identifier
  • Third argument- word
Example:

if(is_elementwithcontent_available("xpath" , "//a[contains(text(),'OFFER')]" , "offer")):
Note

You can use only the provided methods mentioned above.

38. Scrolling in a page

These commands allow you to scroll up or down the automated page before performing other actions.

Command:
scroll_up("NUMERICAL_VALUE")
scroll_up()
scroll_down("NUMERICAL_VALUE")
scroll_down()
Example: scroll_up("1000") scroll_up() scroll_down(1000) scroll_down()

Note

NUMERICAL_VALUE denotes the number of pixels needed to scroll up and down. These values can range between 1 and 100,000 pixels. The default scroll value is 700 pixels.

Was this document helpful?

Would you like to help us improve our documents? Tell us what you think we could do better.


We're sorry to hear that you're not satisfied with the document. We'd love to learn what we could do to improve the experience.


Thanks for taking the time to share your feedback. We'll use your feedback to improve our online help resources.

Shortlink has been copied!