tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

interactive.rst (1489B)


      1 Using the Client Interactively
      2 ==============================
      3 
      4 Once you installed the client and have Marionette running, you can fire
      5 up your favourite interactive python environment and start playing with
      6 Marionette. Let's use a typical python shell:
      7 
      8 .. parsed-literal::
      9   python
     10 
     11 First, import Marionette:
     12 
     13 .. parsed-literal::
     14   from marionette_driver.marionette import Marionette
     15 
     16 Now create the client for this session. Assuming you're using the default
     17 port on a Marionette instance running locally:
     18 
     19 .. parsed-literal::
     20   client = Marionette(host='127.0.0.1', port=2828)
     21   client.start_session()
     22 
     23 This will return some id representing your session id. Now that you've
     24 established a connection, let's start doing interesting things:
     25 
     26 .. parsed-literal::
     27   client.navigate("http://www.mozilla.org")
     28 
     29 Now you're at mozilla.org! You can even verify it using the following:
     30 
     31 .. parsed-literal::
     32   client.get_url()
     33 
     34 You can execute Javascript code in the scope of the web page:
     35 
     36 .. parsed-literal::
     37   client.execute_script("return window.document.title;")
     38 
     39 This will you return the title of the web page as set in the head section
     40 of the HTML document.
     41 
     42 Also you can find elements and click on those. Let's say you want to get
     43 the first link:
     44 
     45 .. parsed-literal::
     46   from marionette_driver import By
     47   first_link = client.find_element(By.TAG_NAME, "a")
     48 
     49 first_link now holds a reference to the first link on the page. You can click it:
     50 
     51 .. parsed-literal::
     52   first_link.click()