"GET_WEB_VALUE" Command

Description: This command is used to retrieve a value from any element on the browser screen and store it in a variable. The default setting allows it to capture a text (HTML tag - Text), but you can also capture other HTML Tags, CSS properties, numbers, strings or boolean values.


Usage Scenarios

 

HTML Tag with attributes

(Scenario 1) Suppose we want to retrieve the text value from the Birthday text box on our Reference app which is found on the Edit Profile page and assign it to a variable.

Procedure: Define a locator with reference name “reference_edit_profile.text.birthday” or use inline XPath where the HTML tag is:

<input type="text" id="birthday" ng-model="ctrl.profile.birthday" placeholder="dd.MM.yyyy" class="form-control ng-pristine ng-valid ng-isolate-scope ng-not-empty ng-valid-date ng-touched" uib-datepicker-popup="dd.MM.yyyy" datepicker-options="ctrl.datePicker.options" is-open="ctrl.isOpen" enable-time="false" close-text="Close" style="">

The XPath is:

//input[@id='birthday'] or //label[contains(@for, 'birthday')]/ancestor::div/descendant::input[@placeholder='dd.MM.yyyy']

In the command options, select the locator and use HTML tag as a Type with "TEXT" as an attribute.
Your steps will look like this:

Web Locator:

image-20240215-161108.png

Inline XPath:

image-20240215-161140.png

 

See the Test Library path: subject7_samples/subject7_advanced_suite/subject7_modify_profile_information

The following video demonstrates how the “Birthday” text box value is retrieved as part of execution of “subject7_modify_profile_information” test case in “subject7_samples” folder. Since the original value is empty, a random one has been entered to simulate this test.

Tip: The Attribute field accepts variables and template injections if you would like to pass values to it.

 

(Scenario 2) Suppose we want to retrieve the hyperlink in the Reference header and assign it to a variable.

Procedure: Define a locator with reference name “reference.link.header” or use an inline XPath where the HTML tag is:

<a class="navbar-brand" href="/">Social Network</a>

The XPath is:

When inspecting the element and looking at the HTML page, we see that “href” contains the URL of the hyperlink. Instead of the default Attribute value of “TEXT”, we can use “href” in the command options. Our step will look like this:

Web Locator:

Inline XPath:

See the video below that demonstrates this scenario. You can also use the snippet below in Advanced View to test it:


(Scenario 3) Suppose we want to retrieve the location (URL) of the profile image in Reference app and assign it to a variable.

Procedure: Define a locator with reference name “reference.image.profile_image” or use an inline XPath where the HTML tag is:

The XPath is:

When inspecting the element and looking at the HTML page, we see that “src” contains the URL of the image. Instead of the default Attribute value of “TEXT”, we can use “src” in the command options. Our step will look like this:

Web Locator:

Inline XPath:

See the video below that demonstrates this scenario. You can also use the snippet below in Advanced View to test it:


CSS with Attributes

(Scenario 4) Suppose we want to retrieve font size of a post under a profile on Reference app and assign it to a variable.

Procedure: Define steps that navigate to Reference app and open the profile to see the posts. Then define a locator for one of the posts or use an inline XPath (you can add a post if the profile does not have any). The HTML tag is similar to:

and the XPath is similar to:

When inspecting the text in Chrome, we see Styles box under the HTML page. We can find any specific attribute using the Filter box.

To retrieve attribute values in Get_Web_Value, we must select CSS as a Type and the attribute will be the one we found in Chrome. For example, let’s use the attribute below which will show the size of the text in the post.

Your step will look like this:

Web Locator:

Inline XPath:

See the video below that demonstrates this scenario. You can also use the snippet below in Advanced View to test it:


Numbers

(Scenario 5) Suppose we have a post containing only numbers in Reference app and we want to retrieve the number and assign it to a variable.

Procedure: Define steps that navigate to Reference app and open the profile to see the posts. Then define a locator or use inline XPath for the text of the post that contains the number.

The HTML tag is similar to:

and the XPath is similar to:

Now all we have to do in the command options is to select Number as Type. Our step should look like this:

Web Locator:

Inline XPath:

See the video below that demonstrates this scenario. You can also use the snippet below in Advanced View to test it:


Strings

(Scenario 6) Suppose we have a post containing a string in Reference app and we want to retrieve the string and assign it to a variable.

Procedure: Define steps that navigate to Reference app and open the profile to see the posts. Then define a locator or use inline XPath for the text of the post that contains the string.

The HTML tag is similar to:

and the XPath is similar to:

Now all we have to do in the command options is to select Number as Type. Our step should look like this:

Web Locator:

Inline XPath:

See the video below that demonstrates this scenario.


Boolean

(Scenario 7) Suppose we have a post containing text in Reference app and we want to use Get_Web_Value with Boolean to see if the text is found or not by returning a “true” or “false” value.

Procedure: Define steps that navigate to Reference app and open the profile to see the posts. Then define a locator or inline XPath for the text of the post that contains the text.

The HTML tag is similar to:

and the XPath is similar to:

Now all we have to do in the command options is to select Boolean as Type. Our step should look like this:

Web Locator:

Inline XPath:

See the video below that demonstrates this scenario:

Javascript

(Scenario 1) Suppose we want to retrieve the number value from a string using Javascript/RegEx and store it in a value.

Procedure: In a step with Get_Web_Value, click Javascript Source Type and add your code in the Script box. For example:

PS: Return statement can always be used to return a value in order to store it in a variable.

Your step will look like this:

 

Once the test is executed, the numbers will be stored in a variable as shown below:

See the video below that demonstrates this scenario. You can use console.log() instead of return if you would like to test on Console.

 

Related pages