<commit_before>The Browser object
==================

The *Browser* object is the main entry point for WebDriver API. With it, you
can explore document, navigate, manipulate mouse, keyboard and many more.

Those browsers are created by a *Client* object, responsible of communication
with server. Here is a full-example for a classic selenium server, running on
*localhost*:

.. code-block:: php

    use WebDriver\Client;

    $client  = new Client('http://localhost:4444/wd/hub');
    $browser = $client->createBrowser('firefox');

If you are in a hurry, you can use this useful shortcut:

.. code-block:: php

    use WebDriver\Browser;

    $browser = Browser::create('firefox', 'http://localhost:4444/wd/hub');

When you're done with the browser object, you need to close it explicitly. See
chapter "Finish the browser" below to know how and why.

Navigation
----------

See the example to see how to manipulate history and go to URLs:

.. code-block:: php

    $browser->open('http://www.google.fr');
    $browser->open('http://www.google.pt');

    $url = $browser->getUrl();

    $browser->back();
    $browser->forward();
    $browser->refresh();

Set timeouts
------------

Different type of timeouts exist with Selenium:

* **script timeout**
* **async script timeout**
* **page load**
* **implicit** (when querying elements)

.. code-block:: php

    $browser->setScriptTimeout(5000); // milliseconds
    $browser->setAsyncScriptTimeout(5000); // milliseconds
    $browser->setPageLoadTimeout(5000); // milliseconds
    $browser->setImplicitTimeout(5n000); // milliseconds

Executing Javascript
--------------------

To run a snippet of Javascript, use the ``execute`` method or the
``executeAsync`` method:

.. code-block:: php

    $res = $browser->execute('return ["foo", "bar", 3, true];');
    var_dump($res); // outputs array("foo", "bar", 3, true);
<commit_msg>Fix typo in Browser doc<commit_after>The Browser object
==================

The *Browser* object is the main entry point for WebDriver API. With it, you
can explore document, navigate, manipulate mouse, keyboard and many more.

Those browsers are created by a *Client* object, responsible of communication
with server. Here is a full-example for a classic selenium server, running on
*localhost*:

.. code-block:: php

    use WebDriver\Client;

    $client  = new Client('http://localhost:4444/wd/hub');
    $browser = $client->createBrowser('firefox');

If you are in a hurry, you can use this useful shortcut:

.. code-block:: php

    use WebDriver\Browser;

    $browser = Browser::create('firefox', 'http://localhost:4444/wd/hub');

When you're done with the browser object, you need to close it explicitly. See
chapter "Finish the browser" below to know how and why.

Navigation
----------

See the example to see how to manipulate history and go to URLs:

.. code-block:: php

    $browser->open('http://www.google.fr');
    $browser->open('http://www.google.pt');

    $url = $browser->getUrl();

    $browser->back();
    $browser->forward();
    $browser->refresh();

Set timeouts
------------

Different type of timeouts exist with Selenium:

* **script timeout**
* **async script timeout**
* **page load**
* **implicit** (when querying elements)

.. code-block:: php

    $browser->setScriptTimeout(5000); // milliseconds
    $browser->setAsyncScriptTimeout(5000); // milliseconds
    $browser->setPageLoadTimeout(5000); // milliseconds
    $browser->setImplicitTimeout(5000); // milliseconds

Executing Javascript
--------------------

To run a snippet of Javascript, use the ``execute`` method or the
``executeAsync`` method:

.. code-block:: php

    $res = $browser->execute('return ["foo", "bar", 3, true];');
    var_dump($res); // outputs array("foo", "bar", 3, true);

{'fraction_non_alphanumeric': 0.1655611568055187, 'fraction_numerical': 0.01379676306712656, 'mean_word_length': 3.6031746031746033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3986440', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1035, 'n_words': 378}