You are here

class NodeElement in Zircon Profile 8

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

Page element node.

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

Hierarchy

Expanded class hierarchy of NodeElement

6 files declare their use of NodeElement
CoreDriver.php in vendor/behat/mink/src/Driver/CoreDriver.php
CoreDriverTest.php in vendor/behat/mink/tests/Driver/CoreDriverTest.php
DriverInterface.php in vendor/behat/mink/src/Driver/DriverInterface.php
NodeElementTest.php in vendor/behat/mink/tests/Element/NodeElementTest.php
PhantomJSDriver.php in vendor/jcalderonzumba/mink-phantomjs-driver/src/PhantomJSDriver.php

... See full list

File

vendor/behat/mink/src/Element/NodeElement.php, line 21

Namespace

Behat\Mink\Element
View source
class NodeElement extends TraversableElement {
  private $xpath;

  /**
   * Initializes node element.
   *
   * @param string  $xpath   element xpath
   * @param Session $session session instance
   */
  public function __construct($xpath, Session $session) {
    $this->xpath = $xpath;
    parent::__construct($session);
  }

  /**
   * Returns XPath for handled element.
   *
   * @return string
   */
  public function getXpath() {
    return $this->xpath;
  }

  /**
   * Returns parent element to the current one.
   *
   * @return NodeElement
   */
  public function getParent() {
    return $this
      ->find('xpath', '..');
  }

  /**
   * Returns current node tag name.
   *
   * The value is always returned in lowercase to allow an easy comparison.
   *
   * @return string
   */
  public function getTagName() {
    return strtolower($this
      ->getDriver()
      ->getTagName($this
      ->getXpath()));
  }

  /**
   * Returns the value of the form field or option element.
   *
   * For checkbox fields, the value is a boolean indicating whether the checkbox is checked.
   * For radio buttons, the value is the value of the selected button in the radio group
   *      or null if no button is selected.
   * For single select boxes, the value is the value of the selected option.
   * For multiple select boxes, the value is an array of selected option values.
   * for file inputs, the return value is undefined given that browsers don't allow accessing
   *      the value of file inputs for security reasons. Some drivers may allow accessing the
   *      path of the file set in the field, but this is not required if it cannot be implemented.
   * For textarea elements and all textual fields, the value is the content of the field.
   * Form option elements, the value is the value of the option (the value attribute or the text
   *      content if the attribute is not set).
   *
   * Calling this method on other elements than form fields or option elements is not allowed.
   *
   * @return string|bool|array
   */
  public function getValue() {
    return $this
      ->getDriver()
      ->getValue($this
      ->getXpath());
  }

  /**
   * Sets the value of the form field.
   *
   * Calling this method on other elements than form fields is not allowed.
   *
   * @param string|bool|array $value
   *
   * @see NodeElement::getValue for the format of the value for each type of field
   */
  public function setValue($value) {
    $this
      ->getDriver()
      ->setValue($this
      ->getXpath(), $value);
  }

  /**
   * Checks whether element has attribute with specified name.
   *
   * @param string $name
   *
   * @return Boolean
   */
  public function hasAttribute($name) {
    return null !== $this
      ->getDriver()
      ->getAttribute($this
      ->getXpath(), $name);
  }

  /**
   * Returns specified attribute value.
   *
   * @param string $name
   *
   * @return string|null
   */
  public function getAttribute($name) {
    return $this
      ->getDriver()
      ->getAttribute($this
      ->getXpath(), $name);
  }

  /**
   * Checks whether an element has a named CSS class.
   *
   * @param string $className Name of the class
   *
   * @return bool
   */
  public function hasClass($className) {
    if ($this
      ->hasAttribute('class')) {
      return in_array($className, preg_split('/\\s+/', $this
        ->getAttribute('class')));
    }
    return false;
  }

  /**
   * Clicks current node.
   */
  public function click() {
    $this
      ->getDriver()
      ->click($this
      ->getXpath());
  }

  /**
   * Presses current button.
   */
  public function press() {
    $this
      ->click();
  }

  /**
   * Double-clicks current node.
   */
  public function doubleClick() {
    $this
      ->getDriver()
      ->doubleClick($this
      ->getXpath());
  }

  /**
   * Right-clicks current node.
   */
  public function rightClick() {
    $this
      ->getDriver()
      ->rightClick($this
      ->getXpath());
  }

  /**
   * Checks current node if it's a checkbox field.
   */
  public function check() {
    $this
      ->getDriver()
      ->check($this
      ->getXpath());
  }

  /**
   * Unchecks current node if it's a checkbox field.
   */
  public function uncheck() {
    $this
      ->getDriver()
      ->uncheck($this
      ->getXpath());
  }

  /**
   * Checks whether current node is checked if it's a checkbox or radio field.
   *
   * Calling this method on any other elements is not allowed.
   *
   * @return Boolean
   */
  public function isChecked() {
    return (bool) $this
      ->getDriver()
      ->isChecked($this
      ->getXpath());
  }

  /**
   * Selects specified option for select field or specified radio button in the group.
   *
   * If the current node is a select box, this selects the option found by its value or
   * its text.
   * If the current node is a radio button, this selects the radio button with the given
   * value in the radio button group of the current node.
   *
   * Calling this method on any other elements is not allowed.
   *
   * @param string  $option
   * @param Boolean $multiple whether the option should be added to the selection for multiple selects
   *
   * @throws ElementNotFoundException when the option is not found in the select box
   */
  public function selectOption($option, $multiple = false) {
    if ('select' !== $this
      ->getTagName()) {
      $this
        ->getDriver()
        ->selectOption($this
        ->getXpath(), $option, $multiple);
      return;
    }
    $opt = $this
      ->find('named', array(
      'option',
      $option,
    ));
    if (null === $opt) {
      throw new ElementNotFoundException($this
        ->getDriver(), 'select option', 'value|text', $option);
    }
    $this
      ->getDriver()
      ->selectOption($this
      ->getXpath(), $opt
      ->getValue(), $multiple);
  }

  /**
   * Checks whether current node is selected if it's a option field.
   *
   * Calling this method on any other elements is not allowed.
   *
   * @return Boolean
   */
  public function isSelected() {
    return (bool) $this
      ->getDriver()
      ->isSelected($this
      ->getXpath());
  }

  /**
   * Attach file to current node if it's a file input.
   *
   * Calling this method on any other elements than file input is not allowed.
   *
   * @param string $path path to file (local)
   */
  public function attachFile($path) {
    $this
      ->getDriver()
      ->attachFile($this
      ->getXpath(), $path);
  }

  /**
   * Checks whether current node is visible on page.
   *
   * @return Boolean
   */
  public function isVisible() {
    return (bool) $this
      ->getDriver()
      ->isVisible($this
      ->getXpath());
  }

  /**
   * Simulates a mouse over on the element.
   */
  public function mouseOver() {
    $this
      ->getDriver()
      ->mouseOver($this
      ->getXpath());
  }

  /**
   * Drags current node onto other node.
   *
   * @param ElementInterface $destination other node
   */
  public function dragTo(ElementInterface $destination) {
    $this
      ->getDriver()
      ->dragTo($this
      ->getXpath(), $destination
      ->getXpath());
  }

  /**
   * Brings focus to element.
   */
  public function focus() {
    $this
      ->getDriver()
      ->focus($this
      ->getXpath());
  }

  /**
   * Removes focus from element.
   */
  public function blur() {
    $this
      ->getDriver()
      ->blur($this
      ->getXpath());
  }

  /**
   * Presses specific keyboard key.
   *
   * @param string|int $char     could be either char ('b') or char-code (98)
   * @param string     $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
   */
  public function keyPress($char, $modifier = null) {
    $this
      ->getDriver()
      ->keyPress($this
      ->getXpath(), $char, $modifier);
  }

  /**
   * Pressed down specific keyboard key.
   *
   * @param string|int $char     could be either char ('b') or char-code (98)
   * @param string     $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
   */
  public function keyDown($char, $modifier = null) {
    $this
      ->getDriver()
      ->keyDown($this
      ->getXpath(), $char, $modifier);
  }

  /**
   * Pressed up specific keyboard key.
   *
   * @param string|int $char     could be either char ('b') or char-code (98)
   * @param string     $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')
   */
  public function keyUp($char, $modifier = null) {
    $this
      ->getDriver()
      ->keyUp($this
      ->getXpath(), $char, $modifier);
  }

  /**
   * Submits the form.
   *
   * Calling this method on anything else than form elements is not allowed.
   */
  public function submit() {
    $this
      ->getDriver()
      ->submitForm($this
      ->getXpath());
  }

}

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
NodeElement::$xpath private property
NodeElement::attachFile public function Attach file to current node if it's a file input.
NodeElement::blur public function Removes focus from element.
NodeElement::check public function Checks current node if it's a checkbox field.
NodeElement::click public function Clicks current node.
NodeElement::doubleClick public function Double-clicks current node.
NodeElement::dragTo public function Drags current node onto other node.
NodeElement::focus public function Brings focus to element.
NodeElement::getAttribute public function Returns specified attribute value.
NodeElement::getParent public function Returns parent element to the current one.
NodeElement::getTagName public function Returns current node tag name.
NodeElement::getValue public function Returns the value of the form field or option element.
NodeElement::getXpath public function Returns XPath for handled element. Overrides ElementInterface::getXpath
NodeElement::hasAttribute public function Checks whether element has attribute with specified name.
NodeElement::hasClass public function Checks whether an element has a named CSS class.
NodeElement::isChecked public function Checks whether current node is checked if it's a checkbox or radio field.
NodeElement::isSelected public function Checks whether current node is selected if it's a option field.
NodeElement::isVisible public function Checks whether current node is visible on page.
NodeElement::keyDown public function Pressed down specific keyboard key.
NodeElement::keyPress public function Presses specific keyboard key.
NodeElement::keyUp public function Pressed up specific keyboard key.
NodeElement::mouseOver public function Simulates a mouse over on the element.
NodeElement::press public function Presses current button.
NodeElement::rightClick public function Right-clicks current node.
NodeElement::selectOption public function Selects specified option for select field or specified radio button in the group.
NodeElement::setValue public function Sets the value of the form field.
NodeElement::submit public function Submits the form.
NodeElement::uncheck public function Unchecks current node if it's a checkbox field.
NodeElement::__construct public function Initializes node element. Overrides Element::__construct
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.