|
33 | 33 | * @method void doubleclick() Double-clicks at the current mouse coordinates (set by moveto). |
34 | 34 | * @method array execute_sql($jsonQuery) Execute SQL. |
35 | 35 | * @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. |
37 | 36 | * @method void forward() Navigates forward in the browser history, if possible. |
38 | 37 | * @method void keys($jsonKeys) Send a sequence of key strokes to the active element. |
39 | 38 | * @method array getLocation() Get the current geo location. |
@@ -559,6 +558,37 @@ protected function getIdentifierPath($identifier) |
559 | 558 | return sprintf('%s/element/%s', $this->url, $identifier); |
560 | 559 | } |
561 | 560 |
|
| 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 | + |
562 | 592 | /** |
563 | 593 | * {@inheritdoc} |
564 | 594 | */ |
|
0 commit comments