Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath for a span based on its text?

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>
like image 556
Rock Avatar asked Sep 27 '17 13:09

Rock


People also ask

What is span tag?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.


1 Answers

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']]
like image 165
Vitaliy Moskalyuk Avatar answered Oct 06 '22 06:10

Vitaliy Moskalyuk