How to Extract/Validate Dynamic Webpage Elements

OmarROmarR Posts: 177 admin

Parasoft: How to Extract/Validate Dynamic Webpage Elements


In some applications, we may come across dynamic elements whose ids/xPaths change every time the web page reloads. This can become challenging to extract/validate such elements. Below are a few techniques used to handle dynamic elements.


Method 1:
There are different Xpath methods/functions to capture these dynamic elements. Initially, we may want to use Chrome’s web-developer tools or Firefox’s Firebug (add-on) tool to find the element’s Xpath. For this example, I will be using a short Chrome web-recording of We will focus on the “Product” menu item and assume it is “dynamic”.

The Web Scenario goes as follows:

1)In a Chrome Browser, inspect (Right-Click) the element

2)A dialog box will open (F12). Hover over or inspect the element to find its appropriate snippet of code:

3)Select the desired line and copy the Xpath

Xpath: //*[@id="menu-item-6192"]/a

4)Select the Browser Contents Viewer and Extract the desired element to generate a validation tool

Assuming that the desired Property value is not present in this wizard, simply choose any one of the available properites and choose “Finish”.

5)Double-click on the new Validation Tool and fill in the fields with the appropriate content

Note: You can Inspect the element if you wish to verify what the Expected Value should be:

6)After filling in all the fields shown below, run your test to verify the results

Method 2:
Two very useful Xpath functions to extract dynamic elements are “Starts-with” and “Contains”
1)“Starts-with” function allows us to identify the dynamic element by the starting text:

2)“Contains” function allows us to identify the dynamic element in scenarios where the element is surrounded by a static value

More information on how to handle dynamic elements can be found in the following link:

Sign In or Register to comment.