ssharma
ssharma

Reputation: 941

Not able to find any element using css or xpath or id on webpage using protractor

My application is a angular app, and I am trying to identify elements on the Webpage using protractor (e2e test) but it does not identify any web element on this page.

I have tried identifying elements using css/xpath/id but it does not recognize elements.

If I inspect these elements in chrome developer tool all elements are present and visible and also I am able to search these elements using css(jquery) or xpath but if I give same expression in my script, protractor does not identify any elements.

eg: I am doing following:

PanelPage.js file:

function PanelPage(){

this.get = function(){

    browser.get('#/test');
}


this.Logo = element(by.css("h1.panel-heading"));
this.Search = element(by.id("showSearchForm"));

test.js file:

var Panel = require('../.././pages/PanelPage');

describe ('my test', function(){


    it('my first test', function() {
        this.page = new Panel();
        this.page.get();
        this.page.Search.click();
        this.page.Logo.click();

    });
});

when I execute this test I get following error: Failed: No element found using locator: By.id("showSearchForm")

If I search id("showSearchForm") in chrome developer tool on same page, element is visible and I am able to find it but when I run my e2e test it fails to identify all the elements on this page.

Note: on other page(like- login/logout) protractor is able to identify elements.

I would appreciate any help on this, thanks in advance.

Upvotes: 0

Views: 412

Answers (1)

Chris Stanley
Chris Stanley

Reputation: 2926

More than likely, you need to wait for the element to appear before searching for it.

browser.wait($('h1.panel-heading').isPresent());

Upvotes: 1

Related Questions