I’m trying to understand the semantics of Selenium DOM locators. The documentation states that they are basically Javascript expressions evaluated to get the target element. But if I try to evaluate eg document.div[0].button[2] (from these examples), I just get Error: TypeError: document.div is undefined.
Is that example invalid? Is this an outdated way of navigating the DOM that’s no longer supported in modern browsers but emulated by Selenium for backward-compatibility? Is there any documentation on how this syntax is meant to work?
Note that I’m not trying to use DOM locators – I’m well aware that using CSS or id or even XPath is cleaner. I, however, need to understand their semantics so I can write code that can convert common DOM locators into XPath locators for use in WebDriver.
There is a great overview of some DOM commands in Selenium here:
http://www.simple-talk.com/dotnet/.net-framework/xpath,-css,-dom-and-selenium-the-rosetta-stone/
It talks a lot about the other selectors as well, but it may be useful in seeing what the commands look like, compared to it’s alternatives. It gives a PDF file of basically what eugene has talked about above too.