What does dom[1] refer to in XPath?

Ask general questions here.
Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

What does dom[1] refer to in XPath?

Post by Fergal » Thu Jan 15, 2015 11:19 am

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!

CookieMonster
Certified Professional
Certified Professional
Posts: 74
Joined: Mon Aug 14, 2006 7:17 pm
Location: CH

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

Post by CookieMonster » Thu Jan 15, 2015 12:50 pm

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

Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

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

Post by Fergal » Fri Jan 16, 2015 12:27 pm

Thanks very much Dan, that's exactly the info I was looking for and it has enabled us to resolve the issue.