forked from php-webdriver/php-webdriver
-
Notifications
You must be signed in to change notification settings - Fork 0
Upload a file
starrychloe edited this page Apr 9, 2015
·
2 revisions
Consider the following <input> html element.
<input type='file' id='file_input'></input>
<?php
// getting the input element
$file_input = $driver->findElement(
WebDriverBy::id('file_input')
);
// set the file detector
$file_input->setFileDetector(new LocalFileDetector());
// upload the file and submit the form
$file_input->sendKeys($file_path)->submit();
If you get an error PHP Fatal error: Uncaught exception 'UnknownServerException' with message 'Expected there to be only 1 file. There were: 0, try to send the file name as an array. There is a bug in the PHP library. It will issue a warning, but it will work in Chrome.
$input->sendKeys(array($file));
PHP Warning: is_file() expects parameter 1 to be a valid path, array given in php-webdriver/lib/remote/LocalFileDetector.php on line 23