Wednesday, June 18, 2014

Using not() in XPath. (ex- you want to write the xpath for the element whose class is not equal to 'abc').

Requirement-
In the below html code, we have to write the xpath for the span (high lighted in green color) tags present inside td tags where td class="closeTrigger" and tr class is not "week-selected".

HTML code-

<tr>
<td class="weekend closeTrigger">
<span>5</span></td>
<td class="closeTrigger">
<span>6</span></td>
<td class="closeTrigger">
<span>7</span></td>
<td class="closeTrigger">
<span>8</span></td>
<td class="closeTrigger">
<span>9</span></td>
<td class="closeTrigger">
<span>10</span></td>
<td class="weekend closeTrigger">
</tr>
<tr class="week-selected">
<td class="weekend closeTrigger date-selected">
<span>11</span></td>
<td class="closeTrigger">
<span>12</span></td>
<td class="closeTrigger">
<span>13</span></td>
<td class="closeTrigger todays-date">
<span>14</span></td>
<td class="closeTrigger">
<span>15</span></td>
<td class="closeTrigger">
<span>16</span></td>
<td class="weekend closeTrigger">
</tr>
<tr>
<td class="weekend closeTrigger">
<span>17</span></td>
<td class="closeTrigger">
<span>18</span></td>
<td class="closeTrigger">
<span>19</span></td>
<td class="closeTrigger">
<span>20</span></td>
<td class="closeTrigger">
<span>21</span></td>
<td class="closeTrigger">
<span>22</span></td>
<td class="weekend closeTrigger">
</tr>


Correct xpath- //tr[not(@class='week-selected')]//td[@class='closeTrigger']//span

For reference, here is the verified snapshot from firepath.




webpage-

No comments:

Post a Comment