author Andrew Halberstadt <ahalberstadt@mozilla.com>
Mon, 24 Nov 2014 09:49:42 -0500
changeset 217408 31b67a7052f40d3d8cf3edba613314bf8e872315
permissions -rw-r--r--
Bug 1088666 - Re-organize marionette client's documentation into basic, advanced and api reference sections, r=AutomatedTester, DONTBUILD because NPOTB

Using the Client Interactively

Once you installed the client and have Marionette running, you can fire
up your favourite interactive python environment and start playing with
Marionette. Let's use a typical python shell:

.. parsed-literal::


First, import Marionette:

.. parsed-literal::
   from marionette import Marionette

Now create the client for this session. Assuming you're using the default
port on a Marionette instance running locally:

.. parsed-literal::

   client = Marionette(host='localhost', port=2828)

This will return some id representing your session id. Now that you've
established a connection, let's start doing interesting things:

.. parsed-literal::

   client.execute_script("alert('o hai there!');")

You should now see this alert pop up! How exciting! Okay, let's do
something practical. Close the dialog and try this:

.. parsed-literal::


Now you're at mozilla.org! You can even verify it using the following:

.. parsed-literal::

You can even find an element and click on it. Let's say you want to get
the first link:

.. parsed-literal::
   from marionette import By
   first_link = client.find_element(By.TAG_NAME, "a")

first_link now holds a reference to the first link on the page. You can click it:

.. parsed-literal::