which one has the highest priority among tag/xpath/text/class/etc

I barely have experience about this area and web programming.

I use this tool for Automation testing.

I want to hit some element that I want but sometimes it failed.

In this case, I try to get a new Xpath by using ‘Object spy in Katalon’ or ‘Google Development Mode’

A friend of mine told me Xpath is usually best way for finding an exact element.

and if there are some elements that have same Xpath or share it, then I should check the other options like tag, text, etc…

Is this the right way?

Could you let me know a better way to catch elements?

 

It really depends on your application under test. Lately, XPath and CSS selector is the most popular way to locate web elements. You can capture XPath using Object Spy in Katalon Studio and modify it following best practices as below:

Use id/name attribute if available (in single page web applications use text() method to locate element).
Use the combination of attributes to make the XPath more specific.
Use the Relative XPath instead of Absolute XPath Statements.
Always avoid using indexes in XPath.
Verify the XPath using chrome developer tools ($x(" [your XPath expression]")).
Using […] to move to the parent of the present node.
Use XPath functions in XPath wherever necessary to better identification.
Use Preceding-sibling or Following-sibling wherever applicable.
Identification of objects with same attribute values.

You can also refer to many other best practices available on the Internet.

Thanks.