2

protractor.e2e-sepc.ts

import {browser, element, by} from 'protractor';

describe('Open the link', () => {

    beforeEach(() => {
        browser.waitForAngularEnabled(false);
        browser.get('url');
        browser.sleep(2000);

    });

    it('Click on more button', () => {
        element(by.id('more').click();
        })
    })

When I ran the above test case on chrome as a browser it ran succcessfully, but when I ran it with chrome --headless browser it fails the spec by displaying error as No element found using locator: By(css selector, *[id="more"])

protractor.config.js

multiCapabilities: [{
        'browserName': 'chrome',
        'chromeOptions': {
            args: ["--headless", "--disable-gpu"]
        }
}]
Aditya
  • 2,358
  • 6
  • 35
  • 61

1 Answers1

2

My assumption is that the 2-second sleep is not enough and you just need to explicitly wait for the presence of the desired element:

var more = element(by.id('more'));
var EC = protractor.ExpectedConditions;

browser.wait(EC.presenceOf(more), 10000)   
more.click();

Note that you had a missing closing parenthesis, but I think that's just a typo:

element(by.id('more')).click();
//               HERE^
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Hi @alecxe I have also tried the method that you worte in your answer following in https://stackoverflow.com/questions/37809915/element-not-visible-error-not-able-to-click-an-element/37815727 this post.My test ran successfully without headless browser and fails in headless browser.The main thing is that only this id fails otherwise every other tcs run succesfully in headless as well as without headless.I have also changed the id. – Aditya Jan 07 '18 at 13:07
  • could you make a video or screenshot in headless mode? Maybe there is no such element and protractor is right :) – Oleksii Jan 08 '18 at 19:19
  • also could you change locator and resolve your issue in such way? – Oleksii Jan 08 '18 at 19:40