xi-test-selenium  master
PHP bindings for Selenium 2
Xi\Test\Selenium\WebElement Class Reference

An element in the HTML document. More...

+ Inheritance diagram for Xi\Test\Selenium\WebElement:

List of all members.

Public Member Functions

 __construct (WebDriver $session, $sessionPath, $id)
 getSeleniumId ()
 Returns the opaque ID Selenium has assigned to this element.
 getSession ()
 Returns the WebDriver instance that this element resides in.
 getId ()
 Returns the HTML id of the element.
 getTagName ()
 getText ()
 Returns the text of the element.
 getAttribute ($attributeName)
 Returns the value of an attribute of the element or null if there is no such attribute.
 isEnabled ()
 Returns whether this (form) element is enabled.
 isDisabled ()
 Returns whether this (form) element is disabled.
 isHidden ()
 Returns whether this element is hidden (e.g.
 click ()
 Clicks on the element.
 fillIn ($text, $clearFirst=true)
 Types text to the element.
 clear ()
 Clears a text(area) input field of all input.
 isSelected ()
 Tells whether this element (option, checkbox or radio button) is selected.
 getParent ()
 Returns the parent element, if any.
 getAncestors ($predicate=null)
 Returns all ancestor elements of this element, deepest i.e.
 getAncestorTags ()
 Returns the tag names of all ancestor elements of this element, deepest i.e.

Protected Member Functions

 makeRelativePostRequest ($relPath, $params)
 createWebElement ($elementId)
 elementGet ($path)
 elementPost ($path, $params=null)
 elementDelete ($path)

Protected Attributes

 $session
 $sessionPath
 $elementId
 $elementPath

Detailed Description

An element in the HTML document.

To use your own subclass, replace the protected createWebElement() in a subclass of WebDriver.

Definition at line 10 of file WebElement.php.


Constructor & Destructor Documentation

Xi\Test\Selenium\WebElement::__construct ( WebDriver session,
sessionPath,
id 
)

Definition at line 17 of file WebElement.php.

    {
        $this->session = $session;
        $this->sessionPath = $sessionPath;
        $this->elementId = (string)$id;
        $this->elementPath = $sessionPath . '/element/' . $id;
    }

Member Function Documentation

Xi\Test\Selenium\WebElement::getSeleniumId ( )

Returns the opaque ID Selenium has assigned to this element.

Returns:
string

Definition at line 29 of file WebElement.php.

    {
        return $this->elementId;
    }
Xi\Test\Selenium\WebElement::getSession ( )

Returns the WebDriver instance that this element resides in.

Returns:
WebDriver

Reimplemented from Xi\Test\Selenium\HasWebElements.

Definition at line 38 of file WebElement.php.

    {
        return $this->session;
    }
Xi\Test\Selenium\WebElement::getId ( )

Returns the HTML id of the element.

Returns:
string

Definition at line 47 of file WebElement.php.

    {
        return $this->getAttribute('id');
    }
Xi\Test\Selenium\WebElement::getTagName ( )

Definition at line 56 of file WebElement.php.

    {
        return $this->elementGet('/name');
    }
Xi\Test\Selenium\WebElement::getText ( )

Returns the text of the element.

Returns:
string

Definition at line 65 of file WebElement.php.

    {
        return $this->elementGet('/text');
    }
Xi\Test\Selenium\WebElement::getAttribute ( attributeName)

Returns the value of an attribute of the element or null if there is no such attribute.

Parameters:
$attributeName
Returns:
string|null

Definition at line 75 of file WebElement.php.

    {
        return $this->elementGet('/attribute/' . $attributeName);
    }
Xi\Test\Selenium\WebElement::isEnabled ( )

Returns whether this (form) element is enabled.

Definition at line 83 of file WebElement.php.

    {
        return $this->elementGet('/enabled');
    }
Xi\Test\Selenium\WebElement::isDisabled ( )

Returns whether this (form) element is disabled.

Definition at line 91 of file WebElement.php.

    {
        return !$this->isEnabled();
    }
Xi\Test\Selenium\WebElement::isHidden ( )

Returns whether this element is hidden (e.g.

by CSS `display: none` or similar).

Definition at line 99 of file WebElement.php.

    {
        return !$this->elementGet('/displayed');
    }
Xi\Test\Selenium\WebElement::click ( )

Clicks on the element.

Definition at line 107 of file WebElement.php.

    {
        $this->elementPost('/click');
    }
Xi\Test\Selenium\WebElement::fillIn ( text,
clearFirst = true 
)

Types text to the element.

The text may contain special keyboard codes. See the constants in the Keys class.

Definition at line 118 of file WebElement.php.

    {
        if ($clearFirst) {
            $this->clear();
        }
        if (!is_array($text)) {
            $text = array((string)$text);
        }
        $this->elementPost('/value', array('value' => $text));
    }
Xi\Test\Selenium\WebElement::clear ( )

Clears a text(area) input field of all input.

Definition at line 132 of file WebElement.php.

    {
        $this->elementPost('/clear');
    }
Xi\Test\Selenium\WebElement::isSelected ( )

Tells whether this element (option, checkbox or radio button) is selected.

To select an element (even an option), `click()` on it.

Returns:
boolean

Definition at line 144 of file WebElement.php.

    {
        return $this->elementGet('/selected');
    }
Xi\Test\Selenium\WebElement::getParent ( )

Returns the parent element, if any.

Returns:
WebElement|null

Definition at line 154 of file WebElement.php.

    {
        return $this->tryFind('..', 'xpath');
    }
Xi\Test\Selenium\WebElement::getAncestors ( predicate = null)

Returns all ancestor elements of this element, deepest i.e.

closest first.

Parameters:
callable | null$predicateAn optional filter predicate function.
Returns:
WebElement[]

Definition at line 165 of file WebElement.php.

    {
        $result = array();
        $p = $this;
        // We test against the tag name because get an error if we try to select
        // the document object (i.e. the thing above <html>).
        // This is a kludge that assumes an HTML document. A better xpath-based solution is no doubt possible.
        while ($p->getTagName() != 'html') {
            $p = $p->getParent();
            if (!$predicate || call_user_func($predicate, $p)) {
                $result[] = $p;
            }
        }
        return $result;
    }
Xi\Test\Selenium\WebElement::getAncestorTags ( )

Returns the tag names of all ancestor elements of this element, deepest i.e.

closest first.

Returns:
string[]

Definition at line 186 of file WebElement.php.

    {
        $result = array();
        foreach ($this->getAncestors() as $ancestor) {
            $result[] = $ancestor->getTagName();
        }
        return $result;
    }
Xi\Test\Selenium\WebElement::makeRelativePostRequest ( relPath,
params 
) [protected]

Reimplemented from Xi\Test\Selenium\HasWebElements.

Definition at line 195 of file WebElement.php.

    {
        return $this->elementPost($relPath, $params);
    }
Xi\Test\Selenium\WebElement::createWebElement ( elementId) [protected]

Reimplemented from Xi\Test\Selenium\HasWebElements.

Definition at line 200 of file WebElement.php.

    {
        return new static($this->session, $this->sessionPath, $elementId);
    }
Xi\Test\Selenium\WebElement::elementGet ( path) [protected]

Definition at line 205 of file WebElement.php.

    {
        return $this->session->getServer()->get($this->elementPath . $path);
    }
Xi\Test\Selenium\WebElement::elementPost ( path,
params = null 
) [protected]

Definition at line 210 of file WebElement.php.

    {
        return $this->session->getServer()->post($this->elementPath . $path, $params);
    }
Xi\Test\Selenium\WebElement::elementDelete ( path) [protected]

Definition at line 215 of file WebElement.php.

    {
        return $this->session->getServer()->delete($this->elementPath . $path);
    }

Member Data Documentation

Xi::Test::Selenium\WebElement::$session [protected]

Definition at line 12 of file WebElement.php.

Xi::Test::Selenium\WebElement::$sessionPath [protected]

Definition at line 13 of file WebElement.php.

Xi::Test::Selenium\WebElement::$elementId [protected]

Definition at line 14 of file WebElement.php.

Xi::Test::Selenium\WebElement::$elementPath [protected]

Definition at line 15 of file WebElement.php.

 All Classes Functions Variables