amit
amit

Reputation: 41

protractor No element found using locator: By(xpath,

Actually I am testing in browser directly and I am getting error saying no element found using locator.

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>

Error:

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)

Upvotes: 0

Views: 3330

Answers (1)

amit
amit

Reputation: 41

This works fine with this code:

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');
    });

Upvotes: 3

Related Questions