CodeceptJS
CodeceptJS copied to clipboard
attachFile() is not working (wdio v4.6.2)
What are you trying to achieve?
Attach a file using WebdriverIO helper function attachFile() by clicking a button evoking a File dialog.
What do you get instead?
unknown error: cannot focus element
Details
Using invalid selector or file path properly throws the errors:
throw new Error(`File at ${file} can not be found on local system`);
throw new Error(`File field ${locator} not found by name|text|CSS|XPath`);
- WebDriverIO version: v4.6.2
- NodeJS Version: v6.11.0
- Operating System: Win10, Chrome 59.0.3071.115 (Official Build) (64-bit)
- Configuration file: From WebDriverIO.js
attachFile(locator, pathToFile) {
let file = path.join(global.codecept_dir, pathToFile);
if (!fileExists(file)) {
throw new Error(`File at ${file} can not be found on local system`);
}
return findFields(this.browser, locator).then((el) => {
this.debug("Uploading " + file);
return this.browser.uploadFile(file).then((res) => {
if (!el.value || el.value.length === 0) {
throw new Error(`File field ${locator} not found by name|text|CSS|XPath`);
}
return this.browser.elementIdValue(el.value[0].ELEMENT, res.value);
});
});
}
My bad.
There is a hidden:
<input ngf-select="uploadImage($file)" ng-disabled="uploading" type="file">
that needs to be selected.