10

I am unable to locate first span with XPath I tried:

//*[@id='student-grid']/div[2]/div[1]/table/tbody/tr[1]/td/span/span[contains(text(), 'Edit School')]

to select span with text - Edit Student button

<tbody role="rowgroup">
<tr class="" data-uid="2f3646c6-213a-4e91-99f9-0fbaa5f7755d" role="row" aria-selected="false">
<td class="select-row" role="gridcell">
<td class="font-md" role="gridcell">marker, Lion</td>
<td role="gridcell">TESTLINK_1_ArchScenario</td>
<td role="gridcell">1st</td>
<td role="gridcell">Not Started</td>
<td role="gridcell"/>
<td role="gridcell"/>
<td role="gridcell">QA Automation TestLink Folders</td>
<td class="k-cell-action" role="gridcell"/>
<td class="k-cell-action detail-view-link font-md" role="gridcell">
<span class="button-grid-action kendo-lexia-tooltip icon-pencil" role="button" title="Edit Student">
<span>Edit Student</span>
</span>
</td>
<td class="k-cell-action archive-link font-md" role="gridcell">
<span class="button-grid-action kendo-lexia-tooltip icon-archive" role="button" title="Archive Student">
<span>Archive Student</span>
</span>
</td>
</tr>
</tbody>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Rock
  • 131
  • 1
  • 1
  • 9

4 Answers4

9

If you want to select span with text - Edit Studen try any of this:

//span[@title='Edit Student']/span
//span[text()='Edit Student']

If you want to select Edit Studen with role="button" try any of this:

//span[@title='Edit Student'][@role='button']
//span[@role='button'][./span[text()='Edit Student']]
//span[@role='button'][./span[.='Edit Student']]
Vitaliy Moskalyuk
  • 2,463
  • 13
  • 15
4

To select the outer span, this XPath,

//span[@role='button' and normalize-space()='Edit School']

will select span elements with a button @role and a normalized string value of Edit School.

To select the inner span, this XPath,

//span[text()='Edit School']

will select span elements with an immediate text node child whose value is Edit School.

You can, of course, further qualify the heritage in either case as needed.

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240
4

simply use can use any of this xpaths

//span[contains(text(),'Edit Student')]
//*[contains(text(),'Edit Student')]
//span [@class='button-grid-action kendo-lexia-tooltip icon-pencil']/span
//span [@title='Edit Student']/span
//span [contains(@title,'Edit Student')]/span
//span [contains(@class,'button-grid-action kendo-lexia-tooltip icon-pencil')]/span
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
2

This should get the span text

//span[.='Edit Student']
Zach
  • 986
  • 7
  • 19