Closed wch closed 8 years ago
I would have preferred to add an upload_file to the element class, but as far as I can tell, the /session/
/file endpoint requires a CSS selector, and will not accept an element's webdriver ID: https://github.com/detro/ghostdriver/blob/873c9d6/src/request_handlers/session_request_handler.js#L212
How about manually creating a selector for the id. I.e. paste0('#', self$get_id())
?
How about manually creating a selector for the id. I.e. paste0('#', self$get_id())?
Oh, wait, it might not have an id, of course.
Oh, wait, it might not have an id, of course.
But we can still create a selector for the element, I suppose, and supply that.
But we can still create a selector for the element, I suppose, and supply that.
How would you create a selector for an arbitrary element?
I suppose the element has to be an upload button, otherwise $upload_file()
does not make sense. And then we could use the tag and attributes of the button to create a selector. Isn't that what you are kind of doing with "selector": "input[name=file]"
?
It does have to be a <input type=file>
, so the selector input[type=file]
would get part of the way there (in the example code I provided above, I assumed the input also had name=file
and so I used that as the selector).
These inputs can have a name
and/or id
, but I don't think either of those attributes is strictly required. I think that's OK though -- I can have it try to construct a selector using the id, then name, and if neither is available, just throw an error. That should cover all realistic use cases.
It should be good to go now.
This adds a
session$upload_file()
method.The webdriver spec says that you should be able to upload files with
element.sendKeys()
, but that currently doesn't work in PhantomJS: ariya/phantomjs#10993The workaround is to POST to
/session/<session_id>/file
with the following:I would have preferred to add an
upload_file
to theelement
class, but as far as I can tell, the/session/<session_id>/file
endpoint requires a CSS selector, and will not accept an element's webdriver ID: https://github.com/detro/ghostdriver/blob/873c9d6/src/request_handlers/session_request_handler.js#L212