Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

File upload hack #89

Closed
wants to merge 2 commits into from

2 participants

@jimevans
Collaborator

Resubmitted pull request after git rebase

This pull request is a gross hack so that file uploading will work with GhostDriver. I'm submitting the pull request only to get the issue on the radar. The hack is clearly marked with comments in the code. To make this work correctly, we will need a proper fix in the PhantomJS project, or we will need to manipulate an attribute of the element so that the PhantomJS uploadFile() method can uniquely find the file upload element on the page.

@detro detro was assigned
@detro
Owner

While almost drunk @jimevans and I concluded that it might be a good idea if PhantomJS offered an API that allowed to "pre-type" the Path to the file, but didn't need an element to "click on" (to open the File Selector Window Popup).

We can than just "click" on that element, that will cause the popup window to be invoked, and PhantomJS should already know how to fill that in.

We should be in business.

@detro detro referenced this pull request from a commit
@detro Handling file upload.
This is the result of the discovery work done by
@jimevans. I have:
- updated PhantomJS to provide a callback "onFilePicker"
- reworked his hack

Closes Issue #89.
b157e79
@detro
Owner

Closed by b157e79

@detro detro closed this
@detro
Owner

@jimevans Can you let me know if this works for you too?
Also, if you have a test case for this, would you mind adding it to the Java tests in here :)
Pretty please? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 9, 2012
  1. @jimevans

    File upload hack

    jimevans authored
Commits on Oct 11, 2012
  1. @jimevans
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 6 deletions.
  1. +22 −6 src/request_handlers/webelement_request_handler.js
View
28 src/request_handlers/webelement_request_handler.js
@@ -212,13 +212,29 @@ ghostdriver.WebElementReqHand = function(idOrElement, session) {
typeRes;
// Ensure all required parameters are available
- if (typeof(postObj) === "object" && typeof(postObj.value) === "object") {
- // Execute the "type" atom
+ if (typeof (postObj) === "object" && typeof (postObj.value) === "object") {
typeRes = _protoParent.getSessionCurrWindow.call(this, _session, req).evaluate(
- typeAtom,
- _getJSON(),
- postObj.value);
-
+ require("./webdriver_atoms.js").get("execute_script"),
+ "return { 'tagName': arguments[0].tagName, 'type': arguments[0].getAttribute('type') };",
+ [_getJSON()]);
+ console.log(JSON.stringify(typeRes));
+ if (typeRes.status === 0 &&
+ typeRes.value.tagName.toLowerCase() === "input" &&
+ typeRes.value.type.toLowerCase() === "file") {
+ var fileName = postObj.value.join("");
+ // This is a total hack. PhantomJS's uploadFile method needs to be
+ // reworked so that we can effectively do this with the "real" element.
+ // The uploadFile method currently sets the file name then clicks on
+ // the file upload element, but attempting this from the GhostDriver
+ // context doesn't seem to work.
+ _protoParent.getSessionCurrWindow.call(this, _session, req).uploadFile("input[type='file']", fileName);
+ } else {
+ // Execute the "type" atom
+ typeRes = _protoParent.getSessionCurrWindow.call(this, _session, req).evaluate(
+ typeAtom,
+ _getJSON(),
+ postObj.value);
+ }
res.respondBasedOnResult(_session, req, typeRes);
return;
}
Something went wrong with that request. Please try again.