CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

attachFile() is not working (wdio v4.6.2)

Open ssimeonoff opened this issue 9 years ago • 1 comments

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);
      });
    });
  }

ssimeonoff avatar Jul 05 '17 11:07 ssimeonoff

My bad. There is a hidden: <input ngf-select="uploadImage($file)" ng-disabled="uploading" type="file"> that needs to be selected.

ssimeonoff avatar Jul 06 '17 08:07 ssimeonoff