Angularjs 需要通过匹配span下的标题文本来定位按钮
如何通过匹配span下的标题文本来定位按钮?Angularjs 需要通过匹配span下的标题文本来定位按钮,angularjs,user-interface,xpath,protractor,Angularjs,User Interface,Xpath,Protractor,如何通过匹配span下的标题文本来定位按钮? 在下面提到的html中,我想根据标记下的文本定位按钮,即'Activities'和'Agents' 因为这两个按钮具有几乎相似的元素结构,并且它们都位于同一父项下。 我用量角器和茉莉花写剧本。 这是我的html: <div class="left-hand-elements layout-column flex-none" flex="none" layout="column"> <div> <span class
在下面提到的html中,我想根据
标记下的文本定位按钮,即'Activities'和'Agents'因为这两个按钮具有几乎相似的元素结构,并且它们都位于同一父项下。 我用量角器和茉莉花写剧本。
这是我的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>
活动
添加
创造新的
代理人
添加
创造新的
尝试下面的XPath:对于活动标题:
//*[@class="layout-row"]/h3[text()="Activities"]
//*[@class="layout-row"]/h3[text()="Agents"]
对于代理标头:
//*[@class="layout-row"]/h3[text()="Activities"]
//*[@class="layout-row"]/h3[text()="Agents"]
要查找标题旁边的按钮,可以尝试以下xpath:
//*[@class="layout-row"]/h3[text()="Activities"]//..//button
及
xpath将在找到标头后导航到父元素,然后找到button标记
有关XPath的更多信息,请查看以下链接:谢谢尼特斯。通过这些,我可以找到两个标题。但是我需要根据标题文本单击按钮。你知道怎么做吗?