Skip to content

Latest commit

 

History

History
61 lines (40 loc) · 1.39 KB

elements.rst

File metadata and controls

61 lines (40 loc) · 1.39 KB

Crawling the page

DOM in browser can be accessed via a fluid interface in library. You need to have a Browser object, and starting from it you can request elements.

Requesting a single element

$title = $browser->element(By::name('title'));
echo $title->getText();

Requesting multiple elements

$links = $browser->elements(By::name('a')); foreach ($links as $link) {

//...

}

Element API

// returns text version of the element
$element->getText();

// returns HTML DOM attribute
$element->getAttribute('name');

// click the element
$element->click();

// indicates if the element is visible on screen
$element->isDisplayed();

// indicates if the element is enabled (for buttons and input)
$element->isEnabled();

// tests if a checkbox or a radio is selected
$element->isSelected();

// test if two elements are referencing same node:
$element->equals($otherElement);

Upload a file

Select your file field, then call method upload on it with as argument the path to your file locally:

$field = $browser->element(By::css('input[type=file]'));

$field->upload('/path/to/local_file');

This method will always upload file over HTTP, even if it's done locally.