1

I do need to locate second node, on basic of same class available in the Table.

There are six results found on webpage, for query : //td[@class='checkboxCollumn']

If I locate it for second node, By using //td[@class='checkboxCollumn'][2] its giving 0 result.

I have tried some other variations : //td[@class='checkboxCollumn']//i[2] and so on its giving 0 result.

What is the correct way to locate it with index ?

Ishita Shah
  • 3,609
  • 1
  • 15
  • 46
  • Possible duplicate of [XPath query to get nth instance of an element](https://stackoverflow.com/questions/4007413/xpath-query-to-get-nth-instance-of-an-element) – gokareless Aug 21 '18 at 07:27

4 Answers4

2

You need to locate like this

(//td[@class='checkboxCollumn'])[2]
Rajagopalan
  • 3,553
  • 2
  • 5
  • 23
  • @IshitaShah Okay sure. @Gaurav solution is correct as well but he missed out the `()`, for an example, try out `(//td[@class='checkboxCollumn'])[position()=2]` – Rajagopalan Aug 21 '18 at 07:26
  • Without round bracket is there any other syntax ? I need to use it on multiple combine xpaths, Which is defined as String. – Ishita Shah Aug 24 '18 at 07:27
  • @IshitaShah I use the wrapper called WATIR which sits on the Ruby Selenium Binding where I don't need to write xpath,for an example, for the above expression I would write, `b.tds(class: "checkboxCollumn").last.click` – Rajagopalan Aug 24 '18 at 07:29
  • Ya, Above is working for 1 one of the solution. And need to use of 2nd requirement, But its not working on combination requirement. Please suggest if there is any other way. – Ishita Shah Aug 24 '18 at 07:31
  • My requirement is same, http://prntscr.com/kmbokf but both xpath are defined separately. So I can't include round brackets on any. – Ishita Shah Aug 24 '18 at 07:39
  • @IshitaShah I did not get your point actually, perhaps you may create a new question,somebody may come along your way – Rajagopalan Aug 24 '18 at 09:17
0

Use this.. to locate second node...

(//td[@class='checkboxCollumn'])[position()=2]

Here position() is 1-indexed i.e. position will start counting from 1

Sodium
  • 766
  • 5
  • 17
0

Try:

(//td[@class='checkboxCollumn'])[2]

With this: //td[@class='checkboxCollumn'][2] you trying to match second element within the same container

gokareless
  • 904
  • 1
  • 7
  • 21
0

try using the (//td[@class='checkboxCollumn'])[2] as [] has higher priority over //.So rememeber to put the expression is brackets when need to specify the exact node of the selected node-list.

In ur case,it will search for all the elements in the document,that are at the second place. Even though above thing not work,let me know.

  • It has nothing to do with *"priority"*. Also note that the same solution has been already provided 3 times and your makes no improvements – Andersson Aug 21 '18 at 07:55