[英]Not able to click the button using element(by.css()) with protractor on ionic2
[英]Protractor getting to click a nested button element
我想单击第二个按钮,但由于两个按钮都相同,因此我无法使用by.class。
div class="ng-view ff-domain ng-scope">
<div class="hero-unit blur-background ng-scope">
<h1></h1>
<h2></h2>
<a class="btn btn-large btn-warning btn-hero" href="/au/shop/glasses?gender=women"></a>
<a class="btn btn-large btn-warning btn-hero" href="/au/shop/glasses?gender=men"></a>
<div class="carousel ng-isolate-scope" carousel="" ng-mouseleave="play()" ng-mouseenter="pause()"></div>
</div>
您可以通过几种不同的方式来执行此操作,例如:
$('.hero-unit a:nth-clild(2)').click();
$('a[href="/au/shop/glasses?gender=men"]').click();
检查量角器API文档:
http://angular.github.io/protractor/#/api
看看CSS选择器:
尝试这个:
var secondbtn = element.all(by.css(".btn").get(1);
secondbtn.click();
我会找到包含所需链接的div,并根据href
属性值区分链接-检查href
结尾是:
var container = element(by.css("div.hero-unit"));
var men = container.element(by.css("a[href$=men]"));
men.click();
请注意建议代码的可读性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.