Axel
Axel

Reputation: 467

Find xpath element depending on two conditions

I want to be able to get an XPATH expression that returns the link of the second column of the row that satisfies two conditions:

  1. The third column contains to Disk_/proc/timer_stats
  2. The fourth column contains to Critical condition

The XML is:

<tbody>
<tr id="table2-0" style="" class="datos2">
<td id="table2-0-0" style=""   class="datos2 "></td>
<td id="table2-0-1" style=""   class="datos2 "><a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&refr=0&filter=all_enabled&filter_standby=all&ag_group=0&tag_filter=0&action_filter=0&id_agente=1&tab=alert&amp;id_alert=1&amp;force_execution=1&refr=60"><img src="http://192.168.50.50:84/pandora_console/images/target.png" data-title="Force" data-use_title_for_force_title="1" class="forced_title" style="border:0px;" alt="Force" /></a></td>
<td id="table2-0-2" style=""   class="datos2 "><span style="font-size: 7.2pt">AvailableMemory</span></td>
<td id="table2-0-3" style=""   class="datos2 "><a class="template_details" href="ajax.php?page=godmode/alerts/alert_templates&get_template_tooltip=1&id_template=1"><img src="http://192.168.50.50:84/pandora_console/images/zoom.png" /></a> <span style="font-size: 7.1pt">Critical condition</span></td>
<td id="table2-0-4" style=""   class="datos2 ">Mail&#x20;to&#x20;Admin <i>(Default)</i></td>
<td id="table2-0-5" style=""   class="datos2 "><span title="Unknown/Never" style="white-space:nowrap;">Unknown</span></td>
<td id="table2-0-6" style=" text-align:center; width:5%;"   class="datos2 "><img src="http://192.168.50.50:84/pandora_console/images/status_sets/default/alert_not_fired.png" data-title="Alert not fired" data-use_title_for_force_title="1" class="forced_title" alt="Alert not fired" /></td>
<td id="table2-0-7" style=" text-align:center; width:5%;"   class="datos2 "><input name="validate[]" type="checkbox" value="1"  id="checkbox-validate"  />
<input id="hidden-validate[]_sent" name="validate[]_sent" type="hidden"  value="1" /></td>
</tr>
<tr id="table2-1" style="" class="datos">
<td id="table2-1-0" style=""   class="datos "></td>
<td id="table2-1-1" style=""   class="datos "><a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&refr=0&filter=all_enabled&filter_standby=all&ag_group=0&tag_filter=0&action_filter=0&id_agente=1&tab=alert&amp;id_alert=2&amp;force_execution=1&refr=60"><img src="http://192.168.50.50:84/pandora_console/images/target.png" data-title="Force" data-use_title_for_force_title="1" class="forced_title" style="border:0px;" alt="Force" /></a></td>
<td id="table2-1-2" style=""   class="datos "><span style="font-size: 7.2pt">Disk_/proc/timer_stats</span></td>
<td id="table2-1-3" style=""   class="datos "><a class="template_details" href="ajax.php?page=godmode/alerts/alert_templates&get_template_tooltip=1&id_template=1"><img src="http://192.168.50.50:84/pandora_console/images/zoom.png" /></a> <span style="font-size: 7.1pt">Critical condition</span></td>
<td id="table2-1-4" style=""   class="datos ">Mail&#x20;to&#x20;Admin <i>(Default)</i></td>
<td id="table2-1-5" style=""   class="datos "><span title="Unknown/Never" style="white-space:nowrap;">Unknown</span></td>
<td id="table2-1-6" style=" text-align:center; width:5%;"   class="datos "><img src="http://192.168.50.50:84/pandora_console/images/status_sets/default/alert_not_fired.png" data-title="Alert not fired" data-use_title_for_force_title="1" class="forced_title" alt="Alert not fired" /></td>
<td id="table2-1-7" style=" text-align:center; width:5%;"   class="datos "><input name="validate[]" type="checkbox" value="2"  id="checkbox-validate1"  />
<input id="hidden-validate[]_sent" name="validate[]_sent" type="hidden"  value="1" /></td>
</tr>
</tbody>

What I expect to get is:

<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&refr=0&filter=all_enabled&filter_standby=all&ag_group=0&tag_filter=0&action_filter=0&id_agente=1&tab=alert&amp;id_alert=2&amp;force_execution=1&refr=60">

Upvotes: 0

Views: 319

Answers (2)

Axel
Axel

Reputation: 467

Thanks to the answer of Keith Hall, I were able to get the XPATH expression:

'//tr[td[3][contains(.,"Disk_/proc/timer_stats")] and td[4][contains(.,"Critical condition")]]/td[2]/a'

Which returns

[<a href=​"index.php?sec=estado&sec2=operation/​agentes/​ver_agente&refr=0&filter=all_…action_filter=0&id_agente=1&tab=alert&id_alert=1&force_execution=1&refr=60">​…​</a>​]

Upvotes: 0

Keith Hall
Keith Hall

Reputation: 16065

/tbody/tr[td[3] = 'Disk_/proc/timer_stats' and normalize-space(td[4]) = 'Critical condition']/td[2]/a
  • /tbody/tr select the tr child of the root tbody where:
  • td[3] = 'Disk_/proc/timer_stats' the third column contains the text Disk_/proc/timer_stats
  • and
  • normalize-space(td[4]) the text content of the fourth column, ignoring leading and trailing spaces
  • = equals
  • 'Critical condition'
  • /td[2]/a then select the second column's link

Upvotes: 2

Related Questions