Forum Discussion

vikas_agarwal's avatar
vikas_agarwal
Frequent Visitor
2 years ago

Data Test Id for Web Elements

Hi,

 

For Desktop:

How we can add test id to the Page Visuals?

 

For Apps:

How we can add test id to the menu options?

 

or any other alternative to make automation smooth?

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi vikas_agarwal 

    What is the testid you want to display, can you provide some sample data or the output you want? so that can provide more suggestion for you.

     

    Best Regards!

    Yolo Zhu

  • vikas_agarwal's avatar
    vikas_agarwal
    Frequent Visitor

    document.getElementsByClassName("visualContainerGroup")

    gives all the visuals on the page.

     

    In Developer Tools,

    I also see name attribute being part of the div, looks like auto generated.

     

    I further checked in (report.json) .pbib file that name is generated when the instance is created, seems it is same  as div attribute value.

    data-testid are present with common values.

    For e.g. if we want to get the title of a card.

    document.getElementsByName("d6c41b97a22e0323e04d")[0].querySelectorAll("[data-testid='visual-title']");

    where d6c41b97a22e0323e04d is a name field.

     

    Can someone confirm, this is the right way or other standard way (API) exists?