class AbstractElementContainer extends WebElement implements IElementContainer (View source)

The base class to be used for making blocks of elements.

To make a class that will represent a block of elements (e.g. web form) create a descendant of this class.

Properties

private NodeElement $_wrappedElement Wrapped element. from WebElement
private IPageFactory $_pageFactory Stores instance of used page factory. from WebElement
private Escaper $_xpathEscaper The XPath escaper. from WebElement

Methods

__construct(NodeElement $wrapped_element, IPageFactory $page_factory)

Initializes html element.

fromNodeElement(NodeElement $node_element, IPageFactory $page_factory)

Creates Element instance based on existing NodeElement instance.

NodeElement|null
find(string $selector, string|array $locator)

Finds first element with specified selector.

NodeElement[]
findAll(string $selector, string|array $locator)

Finds all elements with specified selector.

mixed
waitFor(integer $timeout, callable $callback)

Waits for an element(-s) to appear and returns it.

mixed
__call(string $method, array $arguments)

Proxies all methods to sub-object.

Escaper
getXpathEscaper()

Returns the XPath escaper.

Session
getSession() deprecated

Returns element session.

getPageFactory()

Returns page factory, used during object creation.

string
__toString()

Returns string representation of element.

Expectation
shouldReceive(string $name)

No description

string
getXpath()

Returns XPath for handled element.

NodeElement
getParent()

Returns parent element to the current one.

string
getTagName()

Returns current node tag name.

string|boolean|array
getValue()

Returns the value of the form field or option element.

void
setValue($value)

Sets the value of the form field.

boolean
hasAttribute($name)

Checks whether element has attribute with specified name.

string|null
getAttribute($name)

Returns specified attribute value.

boolean
hasClass($className)

Checks whether an element has a named CSS class.

void
click()

Clicks current node.

void
press()

Presses current button.

void
doubleClick()

Double-clicks current node.

void
rightClick()

Right-clicks current node.

void
check()

Checks current node if it's a checkbox field.

void
uncheck()

Unchecks current node if it's a checkbox field.

boolean
isChecked()

Checks whether current node is checked if it's a checkbox or radio field.

void
selectOption($option, $multiple = false)

Selects specified option for select field or specified radio button in the group.

boolean
isSelected()

Checks whether current node is selected if it's a option field.

void
attachFile($path)

Attach file to current node if it's a file input.

boolean
isVisible()

Checks whether current node is visible on page.

void
mouseOver()

Simulates a mouse over on the element.

void
dragTo(ElementInterface $destination)

Drags current node onto other node.

void
focus()

Brings focus to element.

void
blur()

Removes focus from element.

void
keyPress($char, $modifier = null)

Presses specific keyboard key.

void
keyDown($char, $modifier = null)

Pressed down specific keyboard key.

void
keyUp($char, $modifier = null)

Pressed up specific keyboard key.

void
submit()

Submits the form.

NodeElement|null
findById($id)

Finds element by its id.

boolean
hasLink($locator)

Checks whether element has a link with specified locator.

NodeElement|null
findLink($locator)

Finds link with specified locator.

void
clickLink($locator)

Clicks link with specified locator.

boolean
hasButton($locator)

Checks whether element has a button (input[type=submit|image|button|reset], button) with specified locator.

NodeElement|null
findButton($locator)

Finds button (input[type=submit|image|button|reset], button) with specified locator.

void
pressButton($locator)

Presses button (input[type=submit|image|button|reset], button) with specified locator.

boolean
hasField($locator)

Checks whether element has a field (input, textarea, select) with specified locator.

NodeElement|null
findField($locator)

Finds field (input, textarea, select) with specified locator.

void
fillField($locator, $value)

Fills in field (input, textarea, select) with specified locator.

boolean
hasCheckedField($locator)

Checks whether element has a checkbox with specified locator, which is checked.

boolean
hasUncheckedField($locator)

Checks whether element has a checkbox with specified locator, which is unchecked.

void
checkField($locator)

Checks checkbox with specified locator.

void
uncheckField($locator)

Unchecks checkbox with specified locator.

boolean
hasSelect($locator)

Checks whether element has a select field with specified locator.

void
selectFieldOption($locator, $value, $multiple = false)

Selects option from select field with specified locator.

boolean
hasTable($locator)

Checks whether element has a table with specified locator.

void
attachFileToField($locator, $path)

Attach file to file field with specified locator.

boolean
has($selector, $locator)

Checks whether element with specified selector exists inside the current element.

boolean
isValid()

Checks if an element still exists in the DOM.

string
getText()

Returns element text (inside tag).

string
getHtml()

Returns element inner html.

string
getOuterHtml()

Returns element outer html.

Details

__construct(NodeElement $wrapped_element, IPageFactory $page_factory)

Initializes html element.

Parameters

NodeElement $wrapped_element Wrapped element.
IPageFactory $page_factory Page factory.

static INodeElementAware fromNodeElement(NodeElement $node_element, IPageFactory $page_factory)

Creates Element instance based on existing NodeElement instance.

Parameters

NodeElement $node_element Node element.
IPageFactory $page_factory Page factory.

Return Value

INodeElementAware

NodeElement|null find(string $selector, string|array $locator)

Finds first element with specified selector.

Parameters

string $selector Selector engine name.
string|array $locator Selector locator.

Return Value

NodeElement|null

NodeElement[] findAll(string $selector, string|array $locator)

Finds all elements with specified selector.

Parameters

string $selector Selector engine name.
string|array $locator Selector locator.

Return Value

NodeElement[]

mixed waitFor(integer $timeout, callable $callback)

Waits for an element(-s) to appear and returns it.

Parameters

integer $timeout Maximal allowed waiting time in seconds.
callable $callback Callback, which result is both used as waiting condition and returned. Will receive reference to this element as first argument.

Return Value

mixed

mixed __call(string $method, array $arguments)

Proxies all methods to sub-object.

Parameters

string $method Method to proxy.
array $arguments Method arguments.

Return Value

mixed

Exceptions

ElementException When sub-object doesn't have a specified method.

Escaper getXpathEscaper()

Returns the XPath escaper.

Return Value

Escaper

Session getSession() deprecated

deprecated Accessing the session from the element is deprecated as of 1.2 and will be impossible in 2.0.

Returns element session.

Return Value

Session

protected IPageFactory getPageFactory()

Returns page factory, used during object creation.

Return Value

IPageFactory

string __toString()

Returns string representation of element.

Return Value

string

Expectation shouldReceive(string $name)

Parameters

string $name

Return Value

Expectation

string getXpath()

Returns XPath for handled element.

Return Value

string

NodeElement getParent()

Returns parent element to the current one.

Return Value

NodeElement

string getTagName()

Returns current node tag name.

Return Value

string

string|boolean|array getValue()

Returns the value of the form field or option element.

Return Value

string|boolean|array

void setValue($value)

Sets the value of the form field.

Parameters

$value

Return Value

void

boolean hasAttribute($name)

Checks whether element has attribute with specified name.

Parameters

$name

Return Value

boolean

string|null getAttribute($name)

Returns specified attribute value.

Parameters

$name

Return Value

string|null

boolean hasClass($className)

Checks whether an element has a named CSS class.

Parameters

$className

Return Value

boolean

void click()

Clicks current node.

Return Value

void

void press()

Presses current button.

Return Value

void

void doubleClick()

Double-clicks current node.

Return Value

void

void rightClick()

Right-clicks current node.

Return Value

void

void check()

Checks current node if it's a checkbox field.

Return Value

void

void uncheck()

Unchecks current node if it's a checkbox field.

Return Value

void

boolean isChecked()

Checks whether current node is checked if it's a checkbox or radio field.

Return Value

boolean

void selectOption($option, $multiple = false)

Selects specified option for select field or specified radio button in the group.

Parameters

$option
$multiple

Return Value

void

boolean isSelected()

Checks whether current node is selected if it's a option field.

Return Value

boolean

void attachFile($path)

Attach file to current node if it's a file input.

Parameters

$path

Return Value

void

boolean isVisible()

Checks whether current node is visible on page.

Return Value

boolean

void mouseOver()

Simulates a mouse over on the element.

Return Value

void

void dragTo(ElementInterface $destination)

Drags current node onto other node.

Parameters

ElementInterface $destination

Return Value

void

void focus()

Brings focus to element.

Return Value

void

void blur()

Removes focus from element.

Return Value

void

void keyPress($char, $modifier = null)

Presses specific keyboard key.

Parameters

$char
$modifier

Return Value

void

void keyDown($char, $modifier = null)

Pressed down specific keyboard key.

Parameters

$char
$modifier

Return Value

void

void keyUp($char, $modifier = null)

Pressed up specific keyboard key.

Parameters

$char
$modifier

Return Value

void

void submit()

Submits the form.

Return Value

void

NodeElement|null findById($id)

Finds element by its id.

Parameters

$id

Return Value

NodeElement|null

Checks whether element has a link with specified locator.

Parameters

$locator

Return Value

boolean

Finds link with specified locator.

Parameters

$locator

Return Value

NodeElement|null

Clicks link with specified locator.

Parameters

$locator

Return Value

void

boolean hasButton($locator)

Checks whether element has a button (input[type=submit|image|button|reset], button) with specified locator.

Parameters

$locator

Return Value

boolean

NodeElement|null findButton($locator)

Finds button (input[type=submit|image|button|reset], button) with specified locator.

Parameters

$locator

Return Value

NodeElement|null

void pressButton($locator)

Presses button (input[type=submit|image|button|reset], button) with specified locator.

Parameters

$locator

Return Value

void

boolean hasField($locator)

Checks whether element has a field (input, textarea, select) with specified locator.

Parameters

$locator

Return Value

boolean

NodeElement|null findField($locator)

Finds field (input, textarea, select) with specified locator.

Parameters

$locator

Return Value

NodeElement|null

void fillField($locator, $value)

Fills in field (input, textarea, select) with specified locator.

Parameters

$locator
$value

Return Value

void

boolean hasCheckedField($locator)

Checks whether element has a checkbox with specified locator, which is checked.

Parameters

$locator

Return Value

boolean

boolean hasUncheckedField($locator)

Checks whether element has a checkbox with specified locator, which is unchecked.

Parameters

$locator

Return Value

boolean

void checkField($locator)

Checks checkbox with specified locator.

Parameters

$locator

Return Value

void

void uncheckField($locator)

Unchecks checkbox with specified locator.

Parameters

$locator

Return Value

void

boolean hasSelect($locator)

Checks whether element has a select field with specified locator.

Parameters

$locator

Return Value

boolean

void selectFieldOption($locator, $value, $multiple = false)

Selects option from select field with specified locator.

Parameters

$locator
$value
$multiple

Return Value

void

boolean hasTable($locator)

Checks whether element has a table with specified locator.

Parameters

$locator

Return Value

boolean

void attachFileToField($locator, $path)

Attach file to file field with specified locator.

Parameters

$locator
$path

Return Value

void

boolean has($selector, $locator)

Checks whether element with specified selector exists inside the current element.

Parameters

$selector
$locator

Return Value

boolean

boolean isValid()

Checks if an element still exists in the DOM.

Return Value

boolean

string getText()

Returns element text (inside tag).

Return Value

string

string getHtml()

Returns element inner html.

Return Value

string

string getOuterHtml()

Returns element outer html.

Return Value

string