theHussle
theHussle

Reputation: 321

Protractor - Having an issue getting menu elements

I'm trying to get different menu items to test the links, I've figured out how to do this with a dropdown, but just a general navbar is giving me issues. Here is the protractor code I'm trying to use

// globals for second menu
var mainMenu = element.all(by.id('mainMenu'));

// Second menu
this.dashboard = function() {
    mainMenu.get(0).element(by.linkText('Dashboard')).click();
    browser.waitForAngular();
}

this.content = function() {
    mainMenu.get(1).element(by.linkText('Content')).click();
    browser.waitForAngular();
}


describe('Should Test main Navbar functions', function() {

    it('Dashboard should direct to dashboard page', function() {
        navbar.dashboard();
        expect(browser.getCurrentUrl()).toContain(dashboardUrl);
    });

    it('Content should direct to course page', function() {
        navbar.content();
        expect(browser.getCurrentUrl()).toContain(contentUrl);
    })
});

Html component.

enter image description here

Upvotes: 0

Views: 38

Answers (1)

ssharma
ssharma

Reputation: 941

try this:

this.mainMenu = element(by.id('mainMenu')); this.mainMenu.click(); this.element(by.linkText('Dashboard')).click();

similarly for other menu you can use

this.mainMenu.click(); this.element(by.linkText('Content')).click();

Upvotes: 1

Related Questions