-
Notifications
You must be signed in to change notification settings - Fork 31
webdriverio getAttribute crashes when attribute is not set #43
Comments
My solution is to check |
In the mean time, you can use $$('input[type=checkbox]').map(c => c.getAttribute('checked')) |
@NiGhTTraX thanks for filing the issue. Using the $$('input[type=checkbox]').map(c => c.getAttribute('checked')) or browser.getAttribute('input[type=checkbox]', 'checked') |
@christian-bromann |
This is a bug in the docs then. I don't like |
Ok. Just letting you know that it's currently happening anyway: [17:23:50] DEBUG Queue has stopped!
[17:23:50] DEBUG You can now go into the browser or use the command line as REPL
[17:23:50] DEBUG (To exit, press ^C again or type .exit)
> browser.elements('.toggle')
{ state: 'success',
sessionId: 'dd9d44b1-91a4-412e-b611-79adbb8fcb64',
hCode: 79051361,
value:
[ { ELEMENT: '2', selector: '.toggle', value: [Object], index: 0 },
{ ELEMENT: '3', selector: '.toggle', value: [Object], index: 1 },
{ ELEMENT: '4', selector: '.toggle', value: [Object], index: 2 } ],
class: 'org.openqa.selenium.remote.Response',
selector: '.toggle',
_status: 0 }
> browser.elements('.toggle').getAttribute
[Function: bound ] |
This command browser.elements('.toggle') returns an object though whereas
doesn't |
Ah, you're right. I think I wrote > browser.elements('input[type=checkbox]').getAttribute('checked')
(node:22) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'ELEMENT' of null
(node:22) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> browser.getAttribute('input[type=checkbox]', 'checked')
(node:22) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'ELEMENT' of null
(node:22) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. |
@christian-bromann so is the fix in #44 not good? |
Not sure what this error is about but I was not able to reproduce this with wdio (latest): describe('Mocha Spec Sync example', function() {
it("follows link to new page", function() {
browser.url('http://webdriverjs.christian-bromann.com/');
var selector = 'input[type=checkbox]';
console.log($$(selector).length, 'elements found');
console.log(browser.getAttribute(selector, 'checked'));
console.log(browser.elements(selector).getAttribute('checked'));
});
}); returns:
|
@christian-bromann the problem only occurs when the first matched element doesn't have the attribute you're trying to get. In your example the first checkbox is checked. I can still reproduce the issue with "wdio": "~0.3.3",
"wdio-mocha-framework": "~0.5.8",
"webdriverio": "~4.6.2", |
Reopening. If the input is actually <input type="checkbox"> The execution gets stuck somewhere (probably due to an supressed error in WebdriverIO. Maybe because of |
@christian-bromann please see #44 for a fix. |
Reproduction steps
crashes with
Debugging
By catching unhandled rejections in my code with
I got a stack trace of
That leads us to
is$$Result
which checks if the result is an array of objects that have an.ELEMENT
property. The problem is thatgetAttribute
will returnnull
when the attribute is not set, hence theCannot read property 'ELEMENT' of null
error.The text was updated successfully, but these errors were encountered: