Skip to content

Commit 8c28db7

Browse files
authored
Fix file uploads on new selenium with firefox (#15)
* Fix file uploads on new selenium with firefox * Add docs and fix docs * Better docs
1 parent b686c5f commit 8c28db7

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/WebDriver/Session.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
* @method void doubleclick() Double-clicks at the current mouse coordinates (set by moveto).
3434
* @method array execute_sql($jsonQuery) Execute SQL.
3535
* @method array execute_async($jsonScript) Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
36-
* @method string file($jsonFile) Upload file.
3736
* @method void forward() Navigates forward in the browser history, if possible.
3837
* @method void keys($jsonKeys) Send a sequence of key strokes to the active element.
3938
* @method array getLocation() Get the current geo location.
@@ -559,6 +558,37 @@ protected function getIdentifierPath($identifier)
559558
return sprintf('%s/element/%s', $this->url, $identifier);
560559
}
561560

561+
/**
562+
* Upload a file: /session/:sessionId/se/file (POST)
563+
* : /session/:sessionId/file (POST)
564+
*
565+
* @param array $arguments
566+
* An array with a single key/value. The key should be 'file' and the
567+
* value should be a string containing base64 encoded contents of a file.
568+
*
569+
* @return mixed
570+
*/
571+
public function file(array $arguments)
572+
{
573+
// Since Selenium 4.17 the file URL has been prefixed with /se because
574+
// it is not a W3C command. See
575+
// https://github.com/w3c/webdriver/issues/1355 for discussions about
576+
// the W3C spec and file uploads.
577+
if ($this->isW3C()) {
578+
try {
579+
$result = $this->curl('POST', '/se/file', $arguments);
580+
} catch (Exception $e) {
581+
}
582+
}
583+
584+
// Fallback to pre Selenium 4.17 behaviour and non W3C behaviour.
585+
if (!isset($result)) {
586+
$result = $this->curl('POST', '/file', $arguments);
587+
}
588+
589+
return $result['value'];
590+
}
591+
562592
/**
563593
* {@inheritdoc}
564594
*/

0 commit comments

Comments
 (0)