Page 1 of 1

What does dom[1] refer to in XPath?

Posted: Thu Jan 15, 2015 11:19 am
by Fergal
A test with a step to click on a username form field of a web application, runs fine on my machine. The XPath for the username field repository item is;
/dom[1]//input[#'txtUser']
The same test is not running on a colleagues machine and I believe it might be related to the dom[1] in the XPath. Can you please tell me what the dom[1] refers to or provide suggestions to sources of further info on this?

Many thanks!

Re: What does dom[1] refer to in XPath?

Posted: Thu Jan 15, 2015 12:50 pm
by CookieMonster
Hi Fergal,

If you use dom[1], and if you have for e.g. 10 webpages open, it takes always the active tab. Also if you open on IE 11 the developer tools you have a few dom's open even if you have only one webpage open.

To make repository robust, it make sense to use some attributes in the dom node. For. e.g. dom[@domain~'google']. You can also place a variable in the path and feed the repository variable over the parameters.

Or you change your XPath to /dom//input[#'txtUser'], but this has the disadvantage that the automation can be slow, if you have multiple web sites open.

Cheers
Dan

Re: What does dom[1] refer to in XPath?

Posted: Fri Jan 16, 2015 12:27 pm
by Fergal
Thanks very much Dan, that's exactly the info I was looking for and it has enabled us to resolve the issue.