Skip to content
This repository was archived by the owner on Dec 18, 2019. It is now read-only.

webdriverio getAttribute crashes when attribute is not set #43

@NiGhTTraX

Description

@NiGhTTraX

Reproduction steps

<input type="checkbox">
<input type="checkbox">
$$('input[type=checkbox]').getAttribute('checked');

crashes with

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1):
TypeError: Cannot read property 'ELEMENT' of null

Debugging

By catching unhandled rejections in my code with

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});

I got a stack trace of

Unhandled Rejection at: Promise Promise {
  <rejected> TypeError: Cannot read property 'ELEMENT' of null
    at is$$Result (/usr/src/app/node_modules/wdio-sync/build/index.js:506:63)
    at Object.applyPrototype (/usr/src/app/node_modules/wdio-sync/build/index.js:535:105)
    at Object.<anonymous> (/usr/src/app/node_modules/wdio-sync/build/index.js:452:58)
    at Object.exec (/usr/src/app/node_modules/webdriverio/build/lib/helpers/safeExecute.js:28:24)
    at Object.resolve (/usr/src/app/node_modules/webdriverio/build/lib/webdriverio.js:193:29)
    at /usr/src/app/node_modules/webdriverio/build/lib/webdriverio.js:503:32
    at _fulfilled (/usr/src/app/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/usr/src/app/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/usr/src/app/node_modules/q/q.js:796:13)
    at /usr/src/app/node_modules/q/q.js:604:44 }

That leads us to is$$Result which checks if the result is an array of objects that have an .ELEMENT property. The problem is that getAttribute will return null when the attribute is not set, hence the Cannot read property 'ELEMENT' of null error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions