2016-09-17 45 views
0

我對量角器很陌生,面臨的問題是點擊量角器中'li'ng-repeat內部的對象。任何建議將大大幫助...不能點擊量角器內的'li'ng-repeat'內的對象

我在spec.js中的代碼,它拉起了頁面,登錄&成功獲得標題。但未能點擊對象「LOG FETCH TOOLS」。用味精 「失敗:不使用定位器找到的元素:通過(鏈接文本,LOG FETCH TOOLS)」

describe('Tools Home Page', function() { 
beforeEach(function() { 
return browser.ignoreSynchronization = true; 
}); 

this.title = 'Diagnostic Tools'; 
it('should have a title', function() { 

    browser.driver.get('https://URL'); 
    browser.ignoreSynchronization = true; 
    browser.driver.findElement(by.id('username')).sendKeys('user'); 
    browser.driver.findElement(by.id('password')).sendKeys('pass123'); 
    browser.driver.findElement(by.name('login')).click(); 
    browser.waitForAngular(); 
    expect(browser.getTitle()).toContain('Diagnostic Tools'); 
    element(by.linkText("LOG FETCH TOOLS")).click(); 
    }); 
}); 

對象的位置:

<i><li ng-repeat="(key, value) in tools | groupBy: 'group'" class="ng-scope"> 
<a href="#" data-toggle="collapse" data-target="#group-0" ng- click="toggleIcon($index)" class="ng-binding collapsed"> 
      <i id="grp-0" class="fa fa-plus-circle" ng-class="collapseBtn ? 'fa-minus-circle' : 'fa-plus-circle'" style=""></i> 
LOG FETCH TOOLS 
</a> 
<ul id="group-0" class="nav nav-second-level group collapse" style="height: 0px;"> 
<!-- ngRepeat: tool in value | orderBy: 'disp_name' | filter: search --><li id="tool-40" ng-repeat="tool in value | orderBy: 'disp_name' | filter: search" class="ng-scope"> 
       <a ui-sref="tools.detail({id: tool.id})" ui-sref-active="selected" title="Crawl Logs From Ep Till Smm:- This tool crawls log starting from the entered Entry Point IP till it reaches the SMM machines." class="ng-binding" href="#/tools/detail/40"> 
       Crawl Logs From Ep Till Smm 
       </a> 

+0

是不是AngularJS應用程序?正如你提到的browser.ignoreSynchronization = true;在你的腳本中。如果它是Angular應用程序,則不應在代碼中使用browser.ignoreSynchronization = true。似乎與元素定位器的問題。更改定位器。 to -.by.xpath(「.// a [contains(text(),'LOG FETCH TOOLS')]」) –

+0

感謝您的建議。登錄之前它是非角度的,登錄後它是AngularJS應用程序。一個如何爲我在每個之前刪除。並嘗試與xpath,不工作。 Msg會拋出「找不到使用locator的元素:By(xpath,.//a[contains(text(),'LOG FETCH TOOLS')])」。元素(by.xpath(「.// a [contains(text(),'LOG FETCH TOOLS')]」))。click(); – cmc

+0

謝謝蘇雷什。登錄之前它是非角度的,登錄後它是AngularJS應用程序。任何我如何刪除beforeEach。並嘗試與xpath,不工作。我試着:element(by.xpath(「.// a [contains(text(),'LOG FETCH TOOLS')]」))。click();它仍然給「沒有使用locator找到的元素:By(xpath,.//a[contains(text(),'LOG FETCH TOOLS')])」。 – cmc

回答

0

您應該使用cssContainingText這樣scenarios-

element(by.cssContainingText('a[href="#"]', 'LOG FETCH TOOLS')).click(); 

試試看它應該工作!

+0

非常感謝Ram。有效。 – cmc

0

,而不是by.linkText嘗試使用by.partialLinktext。錨標籤可能有一些領先的白色空間,所以by.linktext不會在這種情況下工作。

+0

不,這也表示找不到任何元素。 browser.findElement(by.partialLinkText(「LOG FETCH TOOLS」))。click(); – cmc