Gėorge
Gėorge

Reputation: 43

Why Protractor can't find element(by.id('mat-input-0'))?

I'm new to automation, and I'm running a very basic test, which was running fine, but just recently it stopped working and I keep receiving the following error :

Failed: script timeout: result was not received in 11 seconds

I looked it up and did some basic debugging and found out that Protractor is not finding the element I'm referring (element(by.id('mat-input-0')) - more below in spec.js code file).
I'm using the latest version of Protractor (5.4.2), along with Jasmine last version (3.4.0). I'm testing on the latest chrome browser.

I tried many online solutions (like using async/await, adding long allScriptsTimeout and defaultTimeoutInterval in the config file (as shown below), calling the element using different locators (by xpath, by id, by tagName,...), trying browser.waitForAngular(); or browser.ignoreSynchronization = true,...) but none worked, so I'm wondering if anyone has any input on what might be the solution? (or maybe what is the real problem?)

Element HTML

<input _ngcontent-mkt-c2="" class="mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-pristine ng-invalid ng-touched" formcontrolname="email" matinput="" name="email" placeholder="Email" required="" type="text" id="mat-input-0" aria-invalid="true" aria-required="true">

Spec.js:

describe('Login', function(){
    it('test 1', async function(){
        await browser.get('the STG URL im testing');


    })
    it('set username', async function(){
        await element(by.id('mat-input-0')).sendKeys('[email protected]');


    })
    it('set password', async function(){
        await element(by.id('mat-input-1')).sendKeys('1234');
    })

})

Conf.js:

exports.config = {  
    seleniumAddress: 'http://localhost:4444/wd/hub',
    allScriptsTimeout: 80000,

    framework: 'jasmine',

    specs: ['spec.js'],

    SELENIUM_PROMISE_MANAGER: false,

    jasmineNodeOpts: {
      defaultTimeoutInterval: 50000
    }
  };

Upvotes: 1

Views: 1171

Answers (1)

Nitin Sahu
Nitin Sahu

Reputation: 621

There could be many reasons for the error you are receiving but as you said you are new to protractor. I would say first go with easy steps.

After protractor installation globally. Your machine must have folder in %appdata%. Go to the directory path AppData\Roaming\npm\node_modules\protractor\example. In this directory you must see two files conf.js and example_spec.js . In spec file replace url by the url you have and also do the same for tests.

Run config file without making any changes in it. and check if it is working fine then there is some configuration problem.

Please go through Protractor learning to learn more about it.

Upvotes: 0

Related Questions