You are here

abstract class TraversableElement in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/behat/mink/src/Element/TraversableElement.php \Behat\Mink\Element\TraversableElement

Traversable element.

@author Konstantin Kudryashov <ever.zet@gmail.com>

Hierarchy

Expanded class hierarchy of TraversableElement

2 files declare their use of TraversableElement
WebAssert.php in vendor/behat/mink/src/WebAssert.php
WebAssert.php in core/modules/simpletest/src/WebAssert.php
Contains \Drupal\simpletest\WebAssert.

File

vendor/behat/mink/src/Element/TraversableElement.php, line 20

Namespace

Behat\Mink\Element
View source
abstract class TraversableElement extends Element {

  /**
   * Finds element by its id.
   *
   * @param string $id element id
   *
   * @return NodeElement|null
   */
  public function findById($id) {
    return $this
      ->find('named', array(
      'id',
      $id,
    ));
  }

  /**
   * Checks whether element has a link with specified locator.
   *
   * @param string $locator link id, title, text or image alt
   *
   * @return Boolean
   */
  public function hasLink($locator) {
    return null !== $this
      ->findLink($locator);
  }

  /**
   * Finds link with specified locator.
   *
   * @param string $locator link id, title, text or image alt
   *
   * @return NodeElement|null
   */
  public function findLink($locator) {
    return $this
      ->find('named', array(
      'link',
      $locator,
    ));
  }

  /**
   * Clicks link with specified locator.
   *
   * @param string $locator link id, title, text or image alt
   *
   * @throws ElementNotFoundException
   */
  public function clickLink($locator) {
    $link = $this
      ->findLink($locator);
    if (null === $link) {
      throw new ElementNotFoundException($this
        ->getDriver(), 'link', 'id|title|alt|text', $locator);
    }
    $link
      ->click();
  }

  /**
   * Checks whether element has a button (input[type=submit|image|button|reset], button) with specified locator.
   *
   * @param string $locator button id, value or alt
   *
   * @return Boolean
   */
  public function hasButton($locator) {
    return null !== $this
      ->findButton($locator);
  }

  /**
   * Finds button (input[type=submit|image|button|reset], button) with specified locator.
   *
   * @param string $locator button id, value or alt
   *
   * @return NodeElement|null
   */
  public function findButton($locator) {
    return $this
      ->find('named', array(
      'button',
      $locator,
    ));
  }

  /**
   * Presses button (input[type=submit|image|button|reset], button) with specified locator.
   *
   * @param string $locator button id, value or alt
   *
   * @throws ElementNotFoundException
   */
  public function pressButton($locator) {
    $button = $this
      ->findButton($locator);
    if (null === $button) {
      throw new ElementNotFoundException($this
        ->getDriver(), 'button', 'id|name|title|alt|value', $locator);
    }
    $button
      ->press();
  }

  /**
   * Checks whether element has a field (input, textarea, select) with specified locator.
   *
   * @param string $locator input id, name or label
   *
   * @return Boolean
   */
  public function hasField($locator) {
    return null !== $this
      ->findField($locator);
  }

  /**
   * Finds field (input, textarea, select) with specified locator.
   *
   * @param string $locator input id, name or label
   *
   * @return NodeElement|null
   */
  public function findField($locator) {
    return $this
      ->find('named', array(
      'field',
      $locator,
    ));
  }

  /**
   * Fills in field (input, textarea, select) with specified locator.
   *
   * @param string $locator input id, name or label
   * @param string $value   value
   *
   * @throws ElementNotFoundException
   *
   * @see NodeElement::setValue
   */
  public function fillField($locator, $value) {
    $field = $this
      ->findField($locator);
    if (null === $field) {
      throw new ElementNotFoundException($this
        ->getDriver(), 'form field', 'id|name|label|value|placeholder', $locator);
    }
    $field
      ->setValue($value);
  }

  /**
   * Checks whether element has a checkbox with specified locator, which is checked.
   *
   * @param string $locator input id, name or label
   *
   * @return Boolean
   *
   * @see NodeElement::isChecked
   */
  public function hasCheckedField($locator) {
    $field = $this
      ->findField($locator);
    return null !== $field && $field
      ->isChecked();
  }

  /**
   * Checks whether element has a checkbox with specified locator, which is unchecked.
   *
   * @param string $locator input id, name or label
   *
   * @return Boolean
   *
   * @see NodeElement::isChecked
   */
  public function hasUncheckedField($locator) {
    $field = $this
      ->findField($locator);
    return null !== $field && !$field
      ->isChecked();
  }

  /**
   * Checks checkbox with specified locator.
   *
   * @param string $locator input id, name or label
   *
   * @throws ElementNotFoundException
   */
  public function checkField($locator) {
    $field = $this
      ->findField($locator);
    if (null === $field) {
      throw new ElementNotFoundException($this
        ->getDriver(), 'form field', 'id|name|label|value', $locator);
    }
    $field
      ->check();
  }

  /**
   * Unchecks checkbox with specified locator.
   *
   * @param string $locator input id, name or label
   *
   * @throws ElementNotFoundException
   */
  public function uncheckField($locator) {
    $field = $this
      ->findField($locator);
    if (null === $field) {
      throw new ElementNotFoundException($this
        ->getDriver(), 'form field', 'id|name|label|value', $locator);
    }
    $field
      ->uncheck();
  }

  /**
   * Checks whether element has a select field with specified locator.
   *
   * @param string $locator select id, name or label
   *
   * @return Boolean
   */
  public function hasSelect($locator) {
    return $this
      ->has('named', array(
      'select',
      $locator,
    ));
  }

  /**
   * Selects option from select field with specified locator.
   *
   * @param string  $locator  input id, name or label
   * @param string  $value    option value
   * @param Boolean $multiple select multiple options
   *
   * @throws ElementNotFoundException
   *
   * @see NodeElement::selectOption
   */
  public function selectFieldOption($locator, $value, $multiple = false) {
    $field = $this
      ->findField($locator);
    if (null === $field) {
      throw new ElementNotFoundException($this
        ->getDriver(), 'form field', 'id|name|label|value', $locator);
    }
    $field
      ->selectOption($value, $multiple);
  }

  /**
   * Checks whether element has a table with specified locator.
   *
   * @param string $locator table id or caption
   *
   * @return Boolean
   */
  public function hasTable($locator) {
    return $this
      ->has('named', array(
      'table',
      $locator,
    ));
  }

  /**
   * Attach file to file field with specified locator.
   *
   * @param string $locator input id, name or label
   * @param string $path    path to file
   *
   * @throws ElementNotFoundException
   *
   * @see NodeElement::attachFile
   */
  public function attachFileToField($locator, $path) {
    $field = $this
      ->findField($locator);
    if (null === $field) {
      throw new ElementNotFoundException($this
        ->getDriver(), 'form field', 'id|name|label|value', $locator);
    }
    $field
      ->attachFile($path);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Element::$driver private property Driver.
Element::$selectorsHandler private property
Element::$session private property
Element::$xpathManipulator private property
Element::elementNotFound Deprecated protected function Builds an ElementNotFoundException.
Element::find public function Finds first element with specified selector inside the current element. Overrides ElementInterface::find
Element::findAll public function Finds all elements with specified selector inside the current element. Overrides ElementInterface::findAll
Element::getDriver protected function Returns element's driver.
Element::getHtml public function Returns element inner html. Overrides ElementInterface::getHtml
Element::getOuterHtml public function Returns element outer html.
Element::getSelectorsHandler Deprecated protected function Returns selectors handler.
Element::getSession Deprecated public function Returns element session. Overrides ElementInterface::getSession
Element::getText public function Returns element text (inside tag). Overrides ElementInterface::getText
Element::has public function Checks whether element with specified selector exists inside the current element. Overrides ElementInterface::has
Element::isValid public function Checks if an element still exists in the DOM. Overrides ElementInterface::isValid
Element::waitFor public function Waits for an element(-s) to appear and returns it. Overrides ElementInterface::waitFor
Element::__construct public function Initialize element. 1
ElementInterface::getXpath public function Returns XPath for handled element. 2
TraversableElement::attachFileToField public function Attach file to file field with specified locator.
TraversableElement::checkField public function Checks checkbox with specified locator.
TraversableElement::clickLink public function Clicks link with specified locator.
TraversableElement::fillField public function Fills in field (input, textarea, select) with specified locator.
TraversableElement::findButton public function Finds button (input[type=submit|image|button|reset], button) with specified locator.
TraversableElement::findById public function Finds element by its id.
TraversableElement::findField public function Finds field (input, textarea, select) with specified locator.
TraversableElement::findLink public function Finds link with specified locator.
TraversableElement::hasButton public function Checks whether element has a button (input[type=submit|image|button|reset], button) with specified locator.
TraversableElement::hasCheckedField public function Checks whether element has a checkbox with specified locator, which is checked.
TraversableElement::hasField public function Checks whether element has a field (input, textarea, select) with specified locator.
TraversableElement::hasLink public function Checks whether element has a link with specified locator.
TraversableElement::hasSelect public function Checks whether element has a select field with specified locator.
TraversableElement::hasTable public function Checks whether element has a table with specified locator.
TraversableElement::hasUncheckedField public function Checks whether element has a checkbox with specified locator, which is unchecked.
TraversableElement::pressButton public function Presses button (input[type=submit|image|button|reset], button) with specified locator.
TraversableElement::selectFieldOption public function Selects option from select field with specified locator.
TraversableElement::uncheckField public function Unchecks checkbox with specified locator.