PHPackages                             akdr/selma - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. akdr/selma

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

akdr/selma
==========

Library for easier use of PHP-Webdriver

v0.6.0(3y ago)01571MITPHPPHP &gt;=8.0CI failing

Since Jun 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ComparicoAB/selma)[ Packagist](https://packagist.org/packages/akdr/selma)[ RSS](/packages/akdr-selma/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (7)Dependencies (4)Versions (14)Used By (0)

Selma
=====

[](#selma)

A PHP-Webdriver wrapper trying to simplify the usage of web-scraping.

Usage
-----

[](#usage)

To use the wrapper you need to have a Selenium Hub up and running.

To set it up, google or use the [docker-compose.yml](docker/docker-compose.yml) in the docker directory. Instructions how to start it once you have docker installed is in the file.

### Navigation

[](#navigation)

Navigation handles the browser navigation and manipulation. Its used by the Element class and needs to be started before you try to scrape.

```
// Example of starting a navigation. The first argument is the location of Selenium Hub and
// the second is Chrome-options.
use ComparicoAB\Selma\Navigation;
$nav = new Navigation('http://localhost:4444/wd/hub', ["window-size=1920,4000", "--headless", "--disable-gpu", "--no-sandbox"]);
```

##### Available methods:

[](#available-methods)

MethodArgumentsCommentReturn typegoToStringMake the browser go to the page in first argument.NavigationcurrentUrlnoneReturns the current URL as a string.StringjavascriptStringExecutes javascript in the browser and returns it output.?StringscrollTo?IntScrolls the page to the first arguments X-value. If omitted is scrolls to the bottom.NavigationscreenshotStringTakes a screenshot of the page and saves it to the absolute path from the first argument.NavigationgetSourcenoneReturns the source from the current URL as a string.StringcliStringPrints a message in the error-logNavigation### Element

[](#element)

The Element class handles everything DOM-related. It searches for DOM-elements, extracts text, filling in inputs and clicking elements.

```
// Example of using the Element to fill out a form and then clicking the submit button.
use Akdr\Selma\Element;
use Akdr\Selma\Navigation;

$nav = new Navigation('http://localhost:4444/wd/hub', ["window-size=1920,4000", "--headless", "--disable-gpu", "--no-sandbox"]);

// First time we need to initiate the Element to use our browser,
// later we can keep using it with the method Set.

// Enter the text "Selma is being used" into the input.
$element = new Element($nav, [
    'selector' => '#form-input',
    'input' => "Selma is being used"
]);

// Click the submit button
$element->set([
    'selector' => '#submit-button',
    'click' => true,
    'delay' => 400000
]);

//Select the response, which is a span without a class or id inside a container.

$container = $element->set([
    'selector' => '.container'
]);

$response = $element->set([
    'element' => $container->element,
    'selector' => 'span',
    'attribute' => 'text'
]);

// Finally, read the response and get the integer while removing the rest of the text.
$response->getValue('int');
```

##### Available methods

[](#available-methods-1)

To get an Element and manipulate it, you can either use the construct or the set() method. They both takes an array as argument and is executed in the order being presented. The selector key has to be set and always (with the exception of 'element') be first.

KeyValue-typeCommentelementFacebook\\WebDriver\\ Remote\\RemoteWebElementIf you need to find a multiple elements and their offspring, you can inject a RemoteWebElement and find its children through 'selector'selectorStringGets the first matching selector with the matching CSS-selector. If the key 'element' is set, it will search inside that Element.attributeStringGets the attribute of the 'selector'. 'text' for the text, 'href' for the link and so on.clickBoolIf true, the browser will try and click the 'selector' element.classStringSets the property $hasClass to true if the 'selector' element has the CSS-class, else false.inputStringPrints the argument into the 'selector' element.pressKeyStringPresses the button passed in the argument, uses constants found [here](http://apigen.juzna.cz/doc/facebook/php-webdriver/class-WebDriverKeys.html)delayIntMakes the browser sleep for the amount of milliseconds in the argumentwaitForElementIntWaits for an element to appear in the browser. The argument sets amount of 0.01 seconds delays it is going to wait.To get the value from attribute, chain -&gt;getValue('int'|'float'|null) on to the construct or set().

##### Public properties

[](#public-properties)

If you need to retrieve the RemoteWebElement, call for the property inside the class named 'element'.

If you need to retrieve the class-bool, call for the property 'hasClass'.

Example:

```
use ComparicoAB\Selma\Navigation;
use ComparicoAB\Selma\Element;

// Setup the browser and initiate the element class.
$nav = new Navigation('http://localhost:4444/wd/hub', ["window-size=1920,4000", "--headless", "--disable-gpu", "--no-sandbox"]);
$element = new Element($nav, []);

//
