XPath更多级别

时间:2015-01-21 09:44:50

标签: html xpath jmeter

是否可以使用xpath在另一个级别中提取某些内容?

在我的表中有不同的不同行。在一个如果它有我的行某处打印“bpmtestinstanz”。我需要获取链接的URL(href),其中链接中的“Instanz abbauen”和里面的表行(tr)“bpmtestinstanz”。但我不知道我应该如何处理链接和印刷文本的不同级别的xpath。

<tr class="htmlobject_tr even" onclick="tr_click(this, 'idp54bf6c72037f1')" onmouseover="tr_hover(this, 'idp54bf6c72037f1')" onmouseout="tr_hover(this, 'idp54bf6c72037f1')">

<td class="htmlobject_td state">
<span class="pill active">
active</span>
</td>

<td class="htmlobject_td config">
<b>
Request ID</b>
 14218305642887<br>
<b>
Hostname</b>
 bpmtestinstanz<br>
<b>
Typ</b>
 KVM VM (localboot)<br>
<b>
CPU</b>
 1<br>
<b>
Speicher</b>
 1.024 GB<br>
<b>
Kernel</b>
 default<br>
<b>
Festplatte</b>
 5 GB<br>
<b>
Image</b>
 13982361680940.cloud_14218305642887_1_<br>
<b>
IP</b>
 192.168.200.166, 172.26.41.105</td>

<td class="htmlobject_td comment">
Requested by user danieldrichardt<hr>
<a class="plugin console" onclick="sshwindow = window.open('https://172.26.41.105:8022','window1722641105', 'location=0,status=0,scrollbars=yes,resizable=yes,width=973,height=500,left=100,top=100,screenX=400,screenY=100'); sshwindow.focus(); return false;" href="#">
Ajaxterm</a>
<a class="plugin novnc" target="_blank" href="api.php?action=novnc&amp;appliance_id=14218305990082">
noVNC</a>
</td>

<td class="htmlobject_td action">
<a data-message="" class="pause" title="Instanz pausieren" href="index.php?cloud_ui=pause&amp;cloudappliance_id[]=14218308730556">
Instanz pausieren</a>
<a data-message="" class="restart" title="Instanz neu starten" href="index.php?cloud_ui=restart&amp;cloudappliance_id[]=14218308730556">
Instanz neu starten</a>
<a data-message="" class="private" title="Privates Image anlegen" href="index.php?cloud_ui=image_private&amp;appliance_id=14218305990082">
Privates Image anlegen</a>
<a data-message="" class="edit" title="Instanz bearbeiten" href="index.php?cloud_ui=appliance_update&amp;cloudappliance_id=14218308730556">
Instanz bearbeiten</a>
<a data-message="" class="remove" title="Instanz abbauen" href="index.php?cloud_ui=deprovision&amp;cloudappliance_id[]=14218308730556">
Instanz abbauen</a>
</td>
</tr>

1 个答案:

答案 0 :(得分:0)

可以做到,但有点复杂。

//tr[td[@class = 'htmlobject_td config' and contains(b[contains(., 'Hostname')]
/following-sibling::text()[1],'bpmtestinstanz')]]/td[@class = 'htmlobject_td action']
/a[contains(.,'Instanz abbauen')]/@href

表示

//tr[td[@class = 'htmlobject_td config'             Select all `tr` elements anywhere in
                                                    the document, but only if they have
                                                    at least one `td` child element that
                                                    has a `class` attribute with the
                                                    value "htmlobject_td config"
and contains(b[contains(., 'Hostname')]             and only if this `td` child element
                                                    also has a child element `b` whose
                                                    text value contains "Hostname"
/following-sibling::text()[1],'bpmtestinstanz')]]   and if the first following sibling
                                                    of this `b` element which is a text
                                                    node contains "bpmtestinstanz"
/td[@class = 'htmlobject_td action']                of this `tr` select a child `td`
                                                    element that has a `class` attribute
                                                    with the value "htmlobject_td action"
/a[contains(.,'Instanz abbauen')]/@href             and select its child `a` if its text
                                                    contains "Instanz abbauen" - and
                                                    finally select the `href` attribute
                                                    of this `a` element.

此解决方案要求“bpmtestinstanz”紧跟在<b>Hostname</b>之后。如果它可以出现在tr元素中的任何位置,则可以稍微简化表达式。