• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Xpath expression to locate second input tag...

 
Micky Morgan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could anyone help me in locating the title of the second input tag in the below sample xml document...

I was trying to use //input[@title='Expand Folder'] and it always points to the first input tag...I want to get the second input tag..

I was also trying this which did not work //table/input[1][@title='Expand Folder']

Please note that I can't use names (eg: @name='wcf3ecfcf5c') since they are dynamically generated...

Could any one help me writing the Xpath expression that gets the second input tag...


<html>
.
.


<table

<th><input title="Expand Folder" name="wcf407a583c" src="/testapp/table/expand.gif" type="image">
<input disabled="true" name="wcf3ecfcf5c" type="hidden"><span class="zoom">Folder_A</span>
</th>

<th><input title="Expand Folder" name="wcf947a9541" src="/testapp/table/expand.gif" type="image">
<input disabled="true" name="wcf2f7dc902" type="hidden"><span class="zoom">Folder_B</span>
</th>

</table>

.
.
</html>

Thanks in advance...
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try with
//table/input[2][@title='Expand Folder']
or
//table/input[position()=2][@title='Expand Folder']


Position in XPath starts with 1 not with 0. See http://www.w3.org/TR/xpath#predicates
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Micky Morgan:
I was trying to use //input[@title='Expand Folder'] and it always points to the first input tag...
Actually it returns a list that contains both of the input elements. Presumably you are then applying something that selects the first entry from the list.
Could any one help me writing the Xpath expression that gets the second input tag...
And then you want to choose the second entry in that list you already have, so do that: //input[@title='Expand Folder'][2]
 
Micky Morgan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the prompt response..but unfortunately none of the optios working..

I am actually clicking (thru automation) the image whether it opens or not..
for that I am using syntax like this...

obj.click("//input[@title='Expand Folder']; --> Always clicks Folder_A..

I tried the above options, it returns null (meaning not found)

I think the best option is to try with text since the text is unique..but that also does not work for me..

click("//input[@title='Expand Folder']/text()='Folder_B") ???

Please suggest the XPath expression that matches Folder_B...

Thanks
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand this "clicking" and "automation" business, except when you say "image" it makes me suspect you really want to get the src attribute from that element. And it would help if the example you had posted were well-formed XML. The fact that isn't implies that we aren't looking at the real data and so we are working in the dark.

However I still say the answer is
//input[@title='Expand Folder'][2]
or perhaps
(//input[@title='Expand Folder'])[2]
 
Micky Morgan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Purushothaman and Paul for prompt responses...

The reason why the above expresions ( //table/input[1] ) did not work because ... table is not immediate parent of input tag as can be seen above...

So the correct XPtah expression that worked for me is..//table/th[2]/input[@title='Expand Folder']

or

//th[2]/input[@title='Expand Folder']


Thanks again for the help...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic