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

LocalFileDetector - PhantomJs 2.0 GhostDriver Windows8 #13302

Closed
chiragmewada opened this issue Jun 5, 2015 · 6 comments
Closed

LocalFileDetector - PhantomJs 2.0 GhostDriver Windows8 #13302

chiragmewada opened this issue Jun 5, 2015 · 6 comments
Labels

Comments

@chiragmewada
Copy link

PHP CALL

 $file_input = $this->driver->findElement(WebDriverBy::xpath(".//*[@id='uploader']/form/input[3]"));
    $file_input->setFileDetector(new LocalFileDetector);
    $file_input->sendKeys($image);

ERROR

PHP Fatal error: Uncaught exception 'WebDriverException' with message 'JSON decoding of remote response failed.
Error code: 4
The response: 'Error - incompatible type of argument(s) in call to _uploadFile(); candidates were
_uploadFile(QString,QStringList)'
' in /var/www/craiglist/php/v3/lib/remote/HttpCommandExecutor.php:241
Stack trace:
#0 /var/www/craiglist/php/v3/lib/remote/RemoteWebDriver.php(491): HttpCommandExecutor->execute(Object(WebDriverCommand))
#1 /var/www/craiglist/php/v3/lib/remote/RemoteExecuteMethod.php(36): RemoteWebDriver->execute('uploadFile', Array)
#2 /var/www/craiglist/php/v3/lib/remote/RemoteWebElement.php(338): RemoteExecuteMethod->execute('uploadFile', Array)
#3 /var/www/craiglist/php/v3/lib/remote/RemoteWebElement.php(299): RemoteWebElement->upload('/var/www/craigl...')
#4 /var/www/craiglist/php/v3/includes/classes/clposter_basic.class.php(478): RemoteWebElement->sendKeys('/var/www/craigl...')
#5 /var/www/craiglist/php/v3/includes/classes/clposter_basic.class.php(487): clposter_basic->uploadImag in /var/www/craiglist/php/v3/lib/remote/HttpCommandExecutor.php on line 241

@radnov
Copy link

radnov commented Jul 29, 2015

I get the same error when trying to attach file using the Codeception framework (with PhantomJS running as GhostDriver).

Anyone have idea how to work around this?

@chiragmewada
Copy link
Author

You need to remove 'multiple' from input tag to make it work
e.g
<input type="file" name="img" multiple>

Following is how i manage to remove using php
$this->driver->executeScript("document.getElementsByName('file')[0].removeAttribute('multiple')", array());

@radnov
Copy link

radnov commented Aug 7, 2015

<input name="MultipleUploadForm[file]" id="MultipleUploadForm_file" type="file">

There's no "multiple" in the input tag of the upload field I'm struggling with. Having said that, it also doesn't accept multiple files to be uploaded when doing it manually.

Any other ideas?

@aniolekx
Copy link

aniolekx commented Sep 7, 2015

same for me, Codecpetion 2.1.2, PhantomJS 2.0.0

@mknecht
Copy link

mknecht commented Nov 21, 2015

I looked into this a fair bit.

Short: Use the UselessFileDetector. Make sure your files are available on the machine where PhantomJS is running.

Longer: As mentioned on SO, this does not happen when running with the PhantomJS driver directly. That's because Ghost Driver PR#324 implemented the uploadFile command incorrectly. Instead of taking a zipped file in the file parameter as the Selenium server does, it's expecting two parameters: selector and filepath.

What does uploadFile do? The Remote WebDriver must assume that PhantomJS is on another machine. Therefore, it needs not only to send the path of the file to the browser (PhantomJS), but also the file itself. The latter is what uploadFile does.

The workaround is to not try to upload the file in the first place, but just send the path.

For Python this means setting the _is_remote attribute:

is_remote = webdriver._is_remote
webdriver._is_remote = False
webdriver.find_element_by_css_selector('input').send_keys(filepath)
webdriver._is_remote = is_remote

Looking at Facebooks PHP version of the remote driver, the decision of whether or not to use uploadFile hinges on the $this->fileDetector. This means for the duration of sendKeys you need to switch to the UselessFileDetector, which is the default. To be sure:

$file_input = $this->driver->findElement(WebDriverBy::xpath(".//*[@id='uploader']/form/input[3]"));
$file_input->setFileDetector(new UselessFileDetector);
$file_input->sendKeys($image);

If your PhantomJS actually runs on a different machine, regardless of which remote driver you use you need to make sure that the files are actually available on the remote server on the path that you are sending.

@stale
Copy link

stale bot commented Dec 30, 2019

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

@stale stale bot closed this as completed Dec 30, 2019
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

4 participants