如何通过匹配span下的标题文本来找到按钮?
在下面提到的html中,我想根据< h3>
标签下的文字找到按钮,即'活动'和'代理'。
由于两个按钮具有几乎相似的元素结构,并且它们都位于同一父节点下。
我正在使用量角器和茉莉花编写脚本。
这是我的HTML:
<div class="left-hand-elements layout-column flex-none" flex="none" layout="column">
<div>
<span class="layout-row" layout="row">
<h3 class="md-title section-header flex" flex="">Activities</h3>
<button class="md-button md-ink-ripple" ng-transclude="" type="button" ng-click="prov.showAddNew('activities', 'create')" aria-label="addCreate New">
<md-icon class="ng-scope ng-isolate-scope material-icons">add</md-icon>
<span class="ng-scope">Create New</span>
</button>
</span>
<md-list class="record-list md-whiteframe-2dp" role="list"></div>
</div>
<div>
<span class="layout-row" layout="row">
<h3 class="md-title section-header flex" flex="">Agents</h3>
<button class="md-button md-ink-ripple" ng-transclude="" type="button" ng-click="prov.showAddNew('agents', 'create')" aria-label="addCreate New">
<md-icon class="ng-scope ng-isolate-scope material-icons">add</md-icon>
<span class="ng-scope">Create New</span>
</button>
</span>
<md-list class="record-list md-whiteframe-2dp" role="list"></div>
</div>
</div>
答案 0 :(得分:1)
尝试以下xpath:
对于活动标题:
//*[@class="layout-row"]/h3[text()="Activities"]
对于Agents标头:
//*[@class="layout-row"]/h3[text()="Agents"]
要查找标题旁边的按钮,您可以尝试以下xpath:
//*[@class="layout-row"]/h3[text()="Activities"]//..//button
和
//*[@class="layout-row"]/h3[text()="Activities"]//..//button
xpath将在找到标题后导航到父元素,然后找到按钮标记。
有关xpath的更多信息,请查看以下链接:
http://www.tizag.com/xmlTutorial/xpathtutorial.php