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

Breadcrumb

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

function Selenium2Driver::executeJsOnElement

Executes JS on a given element - pass in a js script string and {{ELEMENT}} will be replaced with a reference to the element

@example $this->executeJsOnXpath($xpath, 'return {{ELEMENT}}.childNodes.length');

Parameters

Element $element the webdriver element:

string $script the script to execute:

bool $sync whether to run the script synchronously (default is TRUE):

Return value

mixed

6 calls to Selenium2Driver::executeJsOnElement()
Selenium2Driver::deselectAllOptions in vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php
Deselects all options of a multiple select
Selenium2Driver::executeJsOnXpath in vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php
Executes JS on a given element - pass in a js script string and {{ELEMENT}} will be replaced with a reference to the result of the $xpath query
Selenium2Driver::getValue in vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php
Returns element's value by its XPath query.
Selenium2Driver::scrollElementIntoView in vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php
Selenium2Driver::setValue in vendor/lullabot/mink-selenium2-driver/src/Selenium2Driver.php
Sets element's value by its XPath query.

... See full list

File

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

Class

Selenium2Driver
Selenium2 driver.

Namespace

Behat\Mink\Driver

Code

private function executeJsOnElement(Element $element, string $script, bool $sync = true) {
    $script = str_replace('{{ELEMENT}}', 'arguments[0]', $script);
    if ($this->isW3C()) {
        $options = array(
            'script' => $script,
            'args' => [
                [
                    'ELEMENT' => $element->getID(),
                    Element::WEB_ELEMENT_ID => $element->getID(),
                ],
            ],
        );
    }
    else {
        $options = [
            'script' => $script,
            'args' => [
                [
                    'ELEMENT' => $element->getID(),
                ],
            ],
        ];
    }
    if ($sync) {
        return $this->getWebDriverSession()
            ->execute($options);
    }
    return $this->getWebDriverSession()
        ->execute_async($options);
}

API Navigation

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