1

I have been asked on interviews about identifying objects, so I got a little confused. All of the below questions are related to identifying elements, so I combined them together:

  1. Is there any other way to identify objects other than using firebug/firepath or Inspect Element?

  2. Is it true that XPath is not a commonly used identifier, but even when it is used, almost always the relative XPath is used (with 2 slashes)?

  3. Is it true that XPath and CSS are the only two identifiers that are guaranteed to be unique?

2

Is there any other way to identify objects other than using firebug/firepath or Inspect Element?

  • Yes, while browsing a webpage under Windows, press F12 to enter developer mode, you can inspect web object there. Example here You can also acquire HTML objects information by web scraping. E.g. using Python BeautifulSoup.

Is it true that x-path is not a commonly used identifier, but even when it is used, almost always the relative x-path is used (with 2 slashes)?

  • Yes and no. Xpath describes the physical location of a web object, where it is on a HTML hierarchy tree; it is common for a HTML hierarchy tree to change its structure so as the result, Xpath is heavily subject to changes.

  • Relative xpath is more general (less specific) than absolute xpath. As the result, relative xpath is more stable than absoluate xpath.

Is it true that x-path and css are the only two identifiers that are guaranteed to be unique?

  • No, there are a number of different ways to locate an object uniquely. This depends on its context, it is possible to uniquely locate an object with its "id", "class", "text", "tag", "css selector" and "xpath".
2

1 Is there any other way to identify objects other than using firebug/firepath or Inspect Element?

  • By recording a use case with a tool like Selenium IDE
  • By generating the page objects with a tool like Selenium Page Object Generator
  • By manually inspecting the HTML returned by the Selenium

2 Is it true that x-path is not a commonly used identifier, but even when it is used, almost always the relative x-path is used (with 2 slashes)?

An XPath is commonly used in testing when there's a need to match some text or to express relation to an ancestor, descendant, preceding or following element.

A relative XPath is less vulnerable to changes compared to an absolute one, which means less effort to maintain the tests.

3 Is it true that x-path and CSS are the only two identifiers that are guaranteed to be unique?

Each type of identifier can represent a unique web element and each type of identifier can end up matching more than one element. So this question needs a context to be answered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.