Discussion
MUFG Pension & Market Services
IN
Last activity: 26 Mar 2019 14:33 EDT
Anyways to use data-test-id for Selenium automation?
Below are the different types of Locators in Selenium :
- ID
- Name
- Class Name
- Tag Name
- Link Text
- Partial Link Text
- CSS Selector
- XPath
Selenium does not provide facility to use data-test-id, which is unique id provided by Pega. This is the biggest limitation with Selenium for Pega application.
If Selenium can find a way to use data-test-id then it would be very much helpful to automate Pega applications.
Kind Regards,
Fayaz Chaudhari
https://www.linkedin.com/in/fayazchaudhari/
***Updated by moderator: Lochan to add Categories and Group Tag***
-
Reply
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Jouve
FR
Hello,
An exemple of what we do to use selenium with Pega:
xpath = //span[@data-test-id='20160501013618045733253']
xpath=//a[@class="ellipsis"]
xpath=//button[@data-test-id='2014121801251706289770']
xpath=//input[@data-test-id='20160509105143041047433']
MUFG Pension & Market Services
IN
Thanks Nicolas, this helps. Actually we will also the same techniques now a days and more we use Relative Xpath's to find the elements if we are not find using the standard elements.
Accenture
NL
Can it be use for mobile app appium development?
MUFG Pension & Market Services
IN
Amazon.com Inc
US
Hi, I tried using the specified above(data-test-id) however this is not working as expected. Selenium is not finding the element using the data-test-id. When i google it, it says selenium is not returning when the attribute has 3 hyphens in it. Link below.
https://github.com/seleniumhq/selenium/issues/1751
Can you tell me whether its working for you?
Pegasystems Inc.
US
You could also try css selector and see if that works:
css=a[data-test-id='design-template-name-panel']
I am not sure about what version of selenium you are using.
MUFG Pension & Market Services
IN
Thanks Chithra, css might not work always as the weblements are not statics if developers had used dynamic layout in the sections. Instead we can use other Xpath's including css whenever required.
MUFG Pension & Market Services
IN
You need to use the data-test-id in correct format of Xpath. If you are not able to find it then please use other tags to find your respective elements.
Before that, please use correct format of Relative Xpath,
Accenture
NL
Hi,
I have multiple question.
We have Pega iOS app, which i have to automate. Appium is unable to understand the data-test-id as its available on Web context and not Native app context.
Question- 1. If i change the context, im i testing against the mobile app or Pega Server
2. Which is the another identification we can use other than Data-test-id, which does not change even after Pega upgrade.
MUFG Pension & Market Services
IN
Pegasystems Inc.
IN
In such case where you have to use attribute values for fetching a web element apart from standard ones provided by Selenium I would prefer using XPath.
Biggest advantage of using xpath is it gives you flexibility to traverse through nodes.
Coming back to your question as I explained above you can write xpath for using data-test-id as shown below
//input[@data-test-id = 'px-opr-image-ctrl']
above one is for the scenario where you have something static but if there is scenario where you want to fetch element with partial data-test-id then in that case I would suggest you to use contains in Xpath as shown below
//input[contains(@data-test-id, 'px-opr-image')]
Hope my answer helps.
To understand the above 2 lines on writing the XPath
//input - This is to search for the first occurrence of input tag
@ - is used to tell the system that you are referring to one of the attributes in the DOM, so you can refer to any of the attributes inside a tag as I referred to data-test-id.
Rest of the parts are self-explanatory.
For any doubt regarding same please do get in touch with me.
Thanks
Piyush
MUFG Pension & Market Services
IN
Thanks Piyush, Yes Xpath's are always available for finding the elements and are very much helpful for automation,