量角器:找到/单击DOM上的按钮

时间:2017-10-08 20:32:56

标签: javascript html dom protractor

我想知道如何识别并点击底部列出的按钮。

<div class="media-body feed-item">

<div class="media-main" ng-class="{'no-avatar' : feed.type === 'Newsfeed' || feed.type === 'ProductItem' || feed.type === 'PollResult' || feed.type === 'GoalKeyResultUpdate'}">

<div class="meta meta-actions mar-bot10 has-icon" ng-class="{'has-icon': feed.type !== 'Newsfeed' &amp;&amp; feed.type !== 'ProductItem' &amp;&amp; feed.type !== 'PollResult'}">

<ul class="inline clearfix">

<li ng-if="!feed.MeCongrated &amp;&amp; userData.memberActive" class="ng-scope">
<button type="button" class="btn-meta ng-scope" ng-click="congrats(feed)" translate="profile.partials.rec.fee.lik"> Like</button></li>

1 个答案:

答案 0 :(得分:0)

 element(by.ButtonText("Like")).click() 

element(by.partialButtonText("Like")).click()

如果班级是唯一的:

element(by.className("btn-meta ng-scope")).click()

通过css:

element(by.css("btn-meta.ng-scope")).click()

通过css选择的另一种方式:

element(by.css("[ng-click='congrats(feed)']")).click()

按xpath选择:

element(by.xpath(".//button[@ng-click='congrats(feed)']")).click()

或者您可以通过ng-click创建自定义选择器。