Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file uploads on new selenium with firefox #15

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion lib/WebDriver/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* @method void doubleclick() Double-clicks at the current mouse coordinates (set by moveto).
* @method array execute_sql($jsonQuery) Execute SQL.
* @method array execute_async($jsonScript) Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
* @method string file($jsonFile) Upload file.
* @method void forward() Navigates forward in the browser history, if possible.
* @method void keys($jsonKeys) Send a sequence of key strokes to the active element.
* @method array getLocation() Get the current geo location.
Expand Down Expand Up @@ -559,6 +558,37 @@ protected function getIdentifierPath($identifier)
return sprintf('%s/element/%s', $this->url, $identifier);
}

/**
* Upload a file: /session/:sessionId/se/file (POST)
* : /session/:sessionId/file (POST)
*
* @param array $arguments
* An array with a single key/value. The key should be 'file' and the
* value should be a string containing base64 encoded contents of a file.
*
* @return mixed
*/
public function file(array $arguments)
{
// Since Selenium 4.17 the file URL has been prefixed with /se because
// it is not a W3C command. See
// https://github.com/w3c/webdriver/issues/1355 for discussions about
// the W3C spec and file uploads.
if ($this->isW3C()) {
try {
$result = $this->curl('POST', '/se/file', $arguments);
} catch (Exception $e) {
}
}

// Fallback to pre Selenium 4.17 behaviour and non W3C behaviour.
if (!isset($result)) {
$result = $this->curl('POST', '/file', $arguments);
}

return $result['value'];
}

/**
* {@inheritdoc}
*/
Expand Down
Loading