需要XPath帮助 - 选择Checkbox

时间:2016-06-23 13:06:42

标签: html xpath

<h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-header-active ui-corner-top ng-binding ng-scope ui-state-active" ng-click="updateActiveTab($index)" role="tab" ng-class="{'ui-state-active': tabs.active == $index}" ng-if="isUserPermitted($index) && feature.visible" ng-repeat-start="feature in model.features">
<input class="ng-pristine ng-untouched ng-valid" type="checkbox" ng-click="$event.stopPropagation()" style="vertical-align: middle;" ng-change="validateAndUpdateModel($index)" ng-model="ui.featuresEnabled[$index]"/>
 AUS - Demand Response Modes (DRM)                                         
<!-- nasty hack to fix line break for validation error messages -->
<!-- ngIf: tabs.active != $index && (feature.label|translate).length >17 -->
<!-- ngIf: tabs.active == $index && (feature.label|translate).length >17 -->
<span class="glyphicon glyphicon-collapse-up ng-scope" style="float: right; vertical-align: middle; margin-right: 4px" ng-if="tabs.active == $index && (feature.label|translate).length >17"/>
<!-- end ngIf: tabs.active == $index && (feature.label|translate).length >17 -->
<!-- ngIf: (feature.label|translate).length >17 -->
<br class="ng-scope" ng-if="(feature.label|translate).length >17"/>
<!-- end ngIf: (feature.label|translate).length >17 -->
<!-- ngIf: showFeatureValidation(feature) -->
<!-- ngIf: !showFeatureValidation(feature) && showDoubleUsageValidation(feature) -->
<!-- ngIf: tabs.active != $index && (feature.label|translate).length <=17 -->
<!-- ngIf: tabs.active == $index&& (feature.label|translate).length <= 17 -->
</h3>

这是HTML,我需要我的XPath。它包含一个Checkbox和CheckBox的标签(AUS - Demand Response Modes(DRM)),在整个HTML中有多个标签,因此我需要一种方法来确保我选择的复选框包含正确的标签 - 就像在这个例子中一样需求......

到目前为止我尝试的是:

//*[@role='tab' and contains(text(),'Demand')]//*[@type='checkbox']

其他一些版本看起来大致相同,但我无法让它正常工作,它会显示所有复选框,但不会与h3标签中的标签链接,或者根本没有。

1 个答案:

答案 0 :(得分:1)

您可以使用XPath:

role="tab"

它将返回输入复选框(即具有Demand属性的元素的后代),后面紧跟着包含单词的文本节点。