1

我想單擊第二個按鈕,但我無法使用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> 

回答

0

試試這個:

var secondbtn = element.all(by.css(".btn").get(1); 
secondbtn.click(); 
0

我會找到包含所需鏈接div和區分基礎上,href屬性值的鏈接 - 檢查什麼href結尾:

var container = element(by.css("div.hero-unit")); 

var men = container.element(by.css("a[href$=men]")); 
men.click(); 

請注意建議代碼的可讀性。