Hi Experts, need advice
[This question may be silly, but would really really appreciate any help]
What is the best [& recommended] way to identify an object → XPath or ID or text ?
Let’s say for e.g., the textbox field [with the placeholder Company] on the right side of a web-page has both unique ID; as well as a unique text, then which one should I go with → ID or text or should I generate the XPath ?
Please share HTML source of the web page that you want to test.
We can discuss the validity of locators only if a HTML source is given as target. Without any HTML source targeted, we can not evaluate the locators.
Given a target HTML, some locators work, other locators don’t. For example, a locator by ID only works against a HTML with id attributes set; it never works against a HTML without id attributes.
We should be pragmatic. If a locator is valid against a target HTML, it does not matter much which method (ID, text, xpath, css) the locator uses.
However, when we have 2 or more valid locators against a HTML element and if we can chose either of them, we might have some preferences. Possibly, a locator A is better than another locator B
if A is shorter and easier to understand than B.
if A is more robust than B against possible changes in the target HTML markup in future
if A is more reusable than B against many other URLs of similar HTML layout
and, again, the preference would depend on how the target HTML is written.
It is pointless to wonder which method is best without a target HTML source specified.