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 toidentify 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.
- 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.
-
Click_element_by_id/name/linktext/css/xpath("<ELEMENT_ID/NAME/LINKTEXT/CSS/XPATH>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")
When a command has multiple names separated by "/," it indicates that the function is associated with the commands which have various types of primary identifiers.
There are five types of primary identifiers for the click on an element:
click_element_by_id("<ELEMENT_ID>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")
click_element_by_name("<NAME>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")
click_element_by_linktext("<LINKTEXT>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")
click_element_by_css("<CSS>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")
click_element_by_xpath("<XPATH>","<DISPLAY_NAME>","<INTELLIGENT_PLAY_CANDIDATES>")
Web Script Commands
1. Create a step.
load_page("<OPEN_URL>")Example
load_page("https://www.vtitan.com/coporate.html")
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.
load_page("<OPEN_URL>")Example
load_page("https://www.vtitan.com/coporate.html")
OPEN_URL = Base_URL to start a transaction
3. Wait for the page to load until you receive HTTP status code 200.
wait_for_page_to_load()
This has to be included after every action (i.e., which involves URL change)
4. Verify the page status.
verify_page_load_status()
This has to be included after every action (i.e., which involves URL change)
5. Specify authentication credentials.
set_auth_credentials("<DOMAIN>","<USER_NAME>","<PASSWORD>")Example
set_auth_credentials("vtitan.com","xyz","123")
- 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.
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#")
- 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.
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#")
- 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.
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#")
- 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.
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#")
- 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.
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#")
- 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.
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#")
- 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.
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#")
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.
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#")
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.
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#")
index starts from 0.
13. Uncheck the check box.
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.
check_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<DISPLAY_NAME>","<INTELLIGENT_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.
uncheck_by_id/name/css/xpath("<ELEMENT_ID/NAME/CSS/XPATH>","<DISPLAY_NAME>","<INTELLIGENT_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.
select_frame_by_id/name/index/src("<FRAME_ID/NAME/INDEX/SRC>")Example
select_frame("relative=up") - for moving back to top frame from the specific frame.
select_frame_by_id("topframe")
use select_frame("relative=up") after performing any action inside child frame
17. Select a parent window.
selectMainWindow()
18. Select a window before performing any action.
select_window_by_name/title/index("<WINDOW_NAME/TITLE/INDEX>")Example
select_window_by_name("contentWindow")
19. Close the window.
Example
close_window_by_name/title/index("<WINDOW_NAME/TITLE/INDEX>")
close_window() - closes the last selected window
close_window_by_name("contentWindow")
WINDOW_NAME/TITLE/INDEX used here will be the one that you'd have used in select_window.
20. Pause for a specific time.
wait("<TIME_IN_MILLISECONDS>")Example
wait("5000")
Time should be specified in milliseconds.
21. Verify the presence of text on a webpage
assert_text_present("\"<TEXT_1>\" \"<TEXT_2>\"", "true")Example
assert_text_present("CORPORATE","true")
assert_text_present("\"CORPORATE\" \"PRODUCTS\"","true")
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
assert_text_not_present("\"<TEXT_1>\" \"<TEXT_2>\"", "true")Example
assert_text_not_present("error","true")
assert_text_not_present("\"error\" \"warning\"","true")
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
assert_title("<TITLE>")Example
assert_title("vTitan | Safer Health for everyone")
24. Specify confirmation of alert box
assert_confirmation("<ALERT_BOX_MESSAGE>")Example
assert_confirmation("Do you want to log out?")
25. Confirm alert box
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
answer_on_next_prompt("<PROMPT_TEXT>")Example
answer_on_next_prompt("XYZ")
27. Check the prompt message
answer_on_next_prompt("<PROMPT_TEXT>")Example
answer_on_next_prompt("XYZ")
28. Ignore modal dialogue
ignore_modal_dialog("true")
29. Verify your URL
assert_location("<URL>", "true")Example
assert_location("http://vtitan.com/corporate.html", "true")
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.
assert_location("<URL>", "<BOOLEAN>", "<BOOLEAN>")Example
assert_location("http://zylker.com/corporate", "true", "true")
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
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
set_page_load_timeout("45")
Note:This will add an extra wait time of 15 seconds over the default value.
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
navigate_to("www.vtitan.com/products.html")
This will open the page vtitan.com/products without performing any click action.
33. Verify the presence of an element keyword on the webpage
assert_element_keyword_check("<IDENTIFIER>","<IDENTIFIER_ID/NAME/CSS/XPATH>","VALUE")
assert_element_keyword_check("<IDENTIFIER>","<IDENTIFIER_ID/NAME/CSS/XPATH>","VALUE","CONTINUE_ON_FAILURE")
Description:
This command checks if a specific keyword exists within a given website element. It automatically verifies the specified element's presence and visibility. With an optional parameter, we can determine whether to continue or stop the process if the specified keyword assertion fails. In case of failure, the next command will proceed if the optional parameter is set to true.
Example:
assert_element_keyword_check("id","state","California")
assert_element_keyword_check("id","state","California","false")
- IDENTIFIER - The identifier type that should be declared from one of the following : id, name, css, or xpath.
- IDENTIFIER_ID/NAME/CSS/XPATH - Value of the declared identifier.
- VALUE - The keyword that should be matched in the content of the given element.
- CONTINUE_ON_FAILURE (Optional Parameter) - The value must be either true or false. If true, the transaction will continue despite the keyword being absent, marking the monitor as 'Trouble'. If false, the transaction stops immediately, setting the monitor to 'Down'. The default value is true.
34. Verify the presence of an element on the webpage
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")
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
This may not work for AJAX calls.
wait_for_element_visibility("identifier", "identifier_value", timeout)Example
wait_for_element_visibility("id", "country_code", "40")
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
upload_file("identifier", "identifier_value", "file_type", "display_name")Note
The Identifier value could be ID/NAME/LINKTEXT/CSS/XPATH and supported file_types are txt/jpg/png/zip/json/csv/xml.Example
upload_file("id", "state", "jpg", "display_name")
37. If Condition
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")):
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.
scroll_up("NUMERICAL_VALUE") scroll_up() scroll_down("NUMERICAL_VALUE") scroll_down()Example:
scroll_up("1000") scroll_up() scroll_down("1000") scroll_down()
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.