Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 24 Current »

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:

Inline XPath:

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.

get_web_value_birthday.mp4

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:

//a[contains(text(),'Social Network')]

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:

WEB GOTO_URL "https://reference.subject-7.com" HALT ON ERROR 
WEB VALUE_GET RESULT_VARIABLE variable SOURCE ELEMENT XPATH "//a[contains(text(),'Social Network')]" ALIAS "social_network" XML_TYPE "{http://www.w3.org/1999/XSL/Transform}NODE" ATTRIBUTE "href" HALT ON ERROR
get_web_value_href.mp4

(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:

<img ng-src="/images/default-avatar.png" class="profile-photo-lg" src="/images/default-avatar.png">

The XPath is:

//text()[contains(.,'profile')]/ancestor::div/descendant::img
or
//img[@class='profile-photo-lg']

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:

WEB GOTO_URL ${subject7_reference_environment.url} HALT ON ERROR 
CALL FUNCTION subject7_reference_login HALT ON ERROR 
WAIT 2 HALT ON ERROR 
WEB CLICK TARGET LOCATOR subject7_reference_general.link.profile HALT ON ERROR 
WEB CLICK TARGET LOCATOR subject7_reference_main_page.link.profile_settings HALT ON ERROR 
WEB VALUE_GET RESULT_VARIABLE image_src SOURCE ELEMENT XPATH "//text()[contains(.,'profile')]/ancestor::div/descendant::img" ALIAS "" XML_TYPE "{http://www.w3.org/1999/XSL/Transform}NODE" ATTRIBUTE "src" HALT ON ERROR
Get_web_value.mp4

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:

<p class="ng-binding">EXAMPLE</p>

and the XPath is similar to:

//p[contains(text(),'EXAMPLE (4)')]
or
(//p[contains(text(),'EXAMPLE')])[1]

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.

font-size

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:

WEB GOTO_URL ${subject7_reference_environment.url} HALT ON ERROR 
CALL FUNCTION subject7_reference_login HALT ON ERROR 
WEB CLICK TARGET LOCATOR subject7_reference_general.link.profile HALT ON ERROR 
WEB CLICK TARGET LOCATOR subject7_reference_main_page.link.profile_settings HALT ON ERROR 
WAIT 1 HALT ON ERROR 
WEB VALUE_GET RESULT_VARIABLE font_size SOURCE LOCATOR subject7_reference_posts.cell.existing_post XML_TYPE "CSS" ATTRIBUTE "font-size" HALT ON ERROR
Get_web_Value - Css.mp4

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:

<p class="ng-binding" style="" xpath="1">EXAMPLE</p>

and the XPath is similar to:

(//span[contains(text(),'post')]/ancestor::div/descendant::p)[3]
or
//p[@class='ng-binding']

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:

and all of your steps should look like this:

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

WEB GOTO_URL ${subject7_reference_environment.url} HALT ON ERROR 
CALL FUNCTION subject7_reference_login HALT ON ERROR 
WEB CLICK TARGET LOCATOR subject7_reference_general.link.profile HALT ON ERROR 
WEB CLICK TARGET LOCATOR subject7_reference_main_page.link.profile_settings HALT ON ERROR 
WAIT 1 HALT ON ERROR 
WEB VALUE_GET RESULT_VARIABLE get_number SOURCE LOCATOR subject7_reference_posts.cell.existing_post XML_TYPE "{http://www.w3.org/1999/XSL/Transform}NUMBER" ATTRIBUTE "TEXT" HALT ON ERROR
Get_web_Value - number .mp4

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:

<p class="ng-binding" style="">EXAMPLE</p>

and the XPath is similar to:

//p[contains(text(),'EXAMPLE')]

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:

and all our steps should look like this:

See the video below that demonstrates this scenario.

Get_web_Value - string.mp4

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:

<p class="ng-binding" style="" xpath="1">EXAMPLE</p>

and the XPath is similar to:

//p[contains(text(),'EXAMPLE')]

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:

and all our steps should look like this:

See the video below that demonstrates this scenario:

Get_web_Value - boolean.mp4

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:

var text = 'ABC12345 XYZ678'
var numbers = text.replace(/\D/g,'');
return numbers

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.

javascript.mp4

  • No labels