7

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
  • 98,039
  • 18
  • 159
  • 218
Rock
  • 101
  • 1
  • 1
  • 8

4 Answers4

7

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,253
  • 11
  • 15
3

This XPath,

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

will select the span elements with a @role of button and a normalized string value of Edit School. You can, of course, further qualify its heritage as necessary.

See also Testing text() nodes vs string values in XPath

kjhughes
  • 98,039
  • 18
  • 159
  • 218
3

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,363
  • 2
  • 13
  • 35
1

This should get the span text

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