Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

browser.attach and input field FileList/FileUpload #159

Closed
florind opened this issue Jul 30, 2011 · 3 comments
Closed

browser.attach and input field FileList/FileUpload #159

florind opened this issue Jul 30, 2011 · 3 comments
Labels

Comments

@florind
Copy link

florind commented Jul 30, 2011

Hi,

I am trying to use the browser.attach function to test a bit of AJAX on a web page. Here's the input field in the form:

The upload function contains this:
document.upload = function() {
...
var theFile = document.getElementById('uploadfile').files[0];
//upload theFile
var formData = new FormData();
formData.append(theFile.name, theFile);
var xhr = new XMLHttpRequest();
...
xhr.open("POST", '/upload', true);
xhr.send(formData);
...
}

In the zombie test I have:
browser.visit("http://localhost:8080", function(err, browser, status) {
...
browser.attach("input#uploadfile", "/Users/florin/detail.html");
...
}

Now I have 2 issues:

  1. the onchange event is not fired. I am now calling upload() explicitly with: browser.document.upload()
  2. The 'uploadFile' element doesn't contain the files array (it's a FileList that contains FileUpload objects, see http://www.w3schools.com/jsref/dom_obj_fileupload.asp). The error I get running this zombie test is:
    TypeError: Cannot read property '0' of undefined

On a regular browser the code works fine.

What am I doing wrong?
florin

@nisaacson
Copy link

Did you make any progress with the issue? I am having a similar issue on a page with a select dropdown not firing the onChange event.

@pscheit
Copy link
Contributor

pscheit commented Jul 17, 2014

it might not work (despite the change event) because formData is not supported #685

@aik099
Copy link

aik099 commented Jul 17, 2014

For me onchange event is fired twice instead of once, see minkphp/MinkZombieDriver#90. Probably onchange triggering code was changed in 2.x versions of Zombie, that is caused that bug.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants