Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Selenium2Driver.php

function Selenium2Driver::attachFile

Overrides CoreDriver::attachFile

File

vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php, line 920

Class

Selenium2Driver
Selenium2 driver.

Namespace

Behat\Mink\Driver

Code

public function attachFile(string $xpath, string $path) {
    $element = $this->findElement($xpath);
    $this->ensureInputType($element, $xpath, 'file', 'attach a file on');
    // Upload the file to Selenium and use the remote path. This will
    // ensure that Selenium always has access to the file, even if it runs
    // as a remote instance.
    try {
        $remotePath = $this->uploadFile($path);
    } catch (\Exception $e) {
        // File could not be uploaded to remote instance. Use the local path.
        $remotePath = $path;
    }
    if ($this->isW3C()) {
        $element->postValue(array(
            'text' => $remotePath,
        ));
    }
    else {
        $element->postValue(array(
            'value' => array(
                $remotePath,
            ),
        ));
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal