2017-09-28 71 views
-1

其實我在瀏覽器中直接測試和我得到錯誤說沒有使用定位器找到的元素量角器沒有使用定位器找到的元素:通過(XPath中,

spec.js

it('Test for Application Registration text', function() { 
    var ar = browser.findElement(by.xpath('/html/body/admin-app-root/layout/div[1]/cheader/nav/div/div[1]/a[2]')); 
    expect(ar.getAttribute('value')).toEqual('Application Registration'); 
}); 

HTML:

<div _ngcontent-bbu-25="" class="navbar-header"> 
<a _ngcontent-bbu-25="" class="navbar-brand logo navbar-brand-logo" href="/register/core/feature-list"></a> 
<a _ngcontent-bbu-25="" class="navbar-brand navbar-brand-title app-title ellipses" href="/register/core/feature-list">Application Registration</a> 
</div> 

錯誤:

Message:[chrome #01]  Failed: no such element: Unable to locate element: 
{"method":"xpath","selector":"/html/body/adminapproot/layout/div[1]/ 
cheader/nav/div/div[1]/a[2]"}[chrome #01]  
(Session info: chrome=61.0.3163.100)[chrome #01]  
(Driver info:chromedriver=2.32.498550(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a), 
platfor=Windows NT 10.0.14393 x86_64)[chrome #01] 
Stack:[chrome #01] NoSuchElementError: no such element: Unable to locate 
element:{"method":"xpath","selector":"/html/body/admin-app- 
root/layout/div[1]/cheader/nav/div/div[1]/a[2]"}[chrome #01]  
(Session info: chrome=61.0.3163.100)[chrome #01]  
(Driver info:chromedriver=2.32.498550(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a), 
platfor=Windows NT 10.0.14393 x86_64)[chrome #01]   
at WebDriverError(C:\\node_modules\proractor\node_modules\selenium- 
webdriver\lib\error.js:27:5) 
+0

沒有找到任何元素意味着這個xpath沒有元素。 – svgrafov

+0

但他們是目前在該路徑上的鏈接 – amit

+0

哦,是的,對不起。有些邪惡的開發者故意將錯誤加入該庫。 當您和您的應用程序檢查文檔時,DOM可能會有所不同。如果這是您的頁面或鏈接,請考慮添加頁面的代碼,如果這是外部頁面。 – svgrafov

回答

0

這適用於此代碼:

it('Test for Application Registration text', function() { 
     var EC = protractor.ExpectedConditions; 
     var ar = element(by.xpath('/html/body/admin-app-root/layout/div[1]/c-header/nav/div/div[1]/a[2]')); 
     browser.wait(EC.visibilityOf(ar)); 
     expect(ar.getAttribute('value')).toEqual('Application Registration'); 
    }); 
相關問題