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.
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
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.