| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| |
| |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| |
| <title>Selenium Client Driver — Selenium 2.0 documentation</title> |
| |
| <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
| <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
| |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT: './', |
| VERSION: '2.0', |
| COLLAPSE_INDEX: false, |
| FILE_SUFFIX: '.html', |
| HAS_SOURCE: true |
| }; |
| </script> |
| <script type="text/javascript" src="_static/jquery.js"></script> |
| <script type="text/javascript" src="_static/underscore.js"></script> |
| <script type="text/javascript" src="_static/doctools.js"></script> |
| <link rel="top" title="Selenium 2.0 documentation" href="#" /> |
| </head> |
| <body> |
| <div class="related"> |
| <h3>Navigation</h3> |
| <ul> |
| <li class="right" style="margin-right: 10px"> |
| <a href="genindex.html" title="General Index" |
| accesskey="I">index</a></li> |
| <li class="right" > |
| <a href="py-modindex.html" title="Python Module Index" |
| >modules</a> |</li> |
| <li><a href="#">Selenium 2.0 documentation</a> »</li> |
| </ul> |
| </div> |
| |
| <div class="document"> |
| <div class="documentwrapper"> |
| <div class="bodywrapper"> |
| <div class="body"> |
| |
| <div class="section" id="selenium-client-driver"> |
| <h1>Selenium Client Driver<a class="headerlink" href="#selenium-client-driver" title="Permalink to this headline">¶</a></h1> |
| <div class="section" id="introduction"> |
| <h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2> |
| <p>Python language bindings for Selenium WebDriver.</p> |
| <p>The <cite>selenium</cite> package is used automate web browser interaction from Python.</p> |
| <table border="1" class="docutils"> |
| <colgroup> |
| <col width="12%" /> |
| <col width="88%" /> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td><strong>Home</strong>:</td> |
| <td><a class="reference external" href="http://www.seleniumhq.org">http://www.seleniumhq.org</a></td> |
| </tr> |
| <tr class="row-even"><td><strong>Docs</strong>:</td> |
| <td><a class="reference external" href="http://selenium.googlecode.com/git/docs/api/py/api.html">selenium package API</a></td> |
| </tr> |
| <tr class="row-odd"><td><strong>Dev</strong>:</td> |
| <td><a class="reference external" href="https://code.google.com/p/selenium/">https://code.google.com/p/selenium/</a></td> |
| </tr> |
| <tr class="row-even"><td><strong>PyPI</strong>:</td> |
| <td><a class="reference external" href="https://pypi.python.org/pypi/selenium">https://pypi.python.org/pypi/selenium</a></td> |
| </tr> |
| <tr class="row-odd"><td><strong>IRC</strong>:</td> |
| <td><strong>#selenium</strong> channel on freenode</td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Several browsers/drivers are supported (Firefox, Chrome, Internet Explorer, PhantomJS), as well as the Remote protocol.</p> |
| </div> |
| <div class="section" id="supported-python-versions"> |
| <h2>Supported Python Versions<a class="headerlink" href="#supported-python-versions" title="Permalink to this headline">¶</a></h2> |
| <ul class="simple"> |
| <li>Python 2.6, 2.7</li> |
| <li>Python 3.2, 3.3</li> |
| </ul> |
| </div> |
| <div class="section" id="installing"> |
| <h2>Installing<a class="headerlink" href="#installing" title="Permalink to this headline">¶</a></h2> |
| <p>If you have <a class="reference external" href="http://www.pip-installer.org">pip</a> on your system, you can simply install or upgrade the Python bindings:</p> |
| <div class="highlight-python"><pre>pip install -U selenium</pre> |
| </div> |
| <p>Alternately, you can download the source distribution from <a class="reference external" href="http://pypi.python.org/pypi/selenium">PyPI</a> (e.g. selenium-2.40.tar.gz), unarchive it, and run:</p> |
| <div class="highlight-python"><pre>python setup.py install</pre> |
| </div> |
| <p>Note: both of the methods described above install <cite>selenium</cite> as a system-wide package That will require administrative/root access to ther machine. You may consider using a <a class="reference external" href="http://www.virtualenv.org/">virtualenv</a> to create isolated Python environments instead.</p> |
| </div> |
| <div class="section" id="example-0"> |
| <h2>Example 0:<a class="headerlink" href="#example-0" title="Permalink to this headline">¶</a></h2> |
| <ul class="simple"> |
| <li>open a new Firefox browser</li> |
| <li>load the page at the given URL</li> |
| </ul> |
| <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">selenium</span> <span class="kn">import</span> <span class="n">webdriver</span> |
| |
| <span class="n">browser</span> <span class="o">=</span> <span class="n">webdriver</span><span class="o">.</span><span class="n">Firefox</span><span class="p">()</span> |
| <span class="n">browser</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'http://seleniumhq.org/'</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="example-1"> |
| <h2>Example 1:<a class="headerlink" href="#example-1" title="Permalink to this headline">¶</a></h2> |
| <ul class="simple"> |
| <li>open a new Firefox browser</li> |
| <li>load the Yahoo homepage</li> |
| <li>search for “seleniumhq”</li> |
| <li>close the browser</li> |
| </ul> |
| <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">selenium</span> <span class="kn">import</span> <span class="n">webdriver</span> |
| <span class="kn">from</span> <span class="nn">selenium.webdriver.common.keys</span> <span class="kn">import</span> <span class="n">Keys</span> |
| |
| <span class="n">browser</span> <span class="o">=</span> <span class="n">webdriver</span><span class="o">.</span><span class="n">Firefox</span><span class="p">()</span> |
| |
| <span class="n">browser</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'http://www.yahoo.com'</span><span class="p">)</span> |
| <span class="k">assert</span> <span class="s">'Yahoo!'</span> <span class="ow">in</span> <span class="n">browser</span><span class="o">.</span><span class="n">title</span> |
| |
| <span class="n">elem</span> <span class="o">=</span> <span class="n">browser</span><span class="o">.</span><span class="n">find_element_by_name</span><span class="p">(</span><span class="s">'p'</span><span class="p">)</span> <span class="c"># Find the search box</span> |
| <span class="n">elem</span><span class="o">.</span><span class="n">send_keys</span><span class="p">(</span><span class="s">'seleniumhq'</span> <span class="o">+</span> <span class="n">Keys</span><span class="o">.</span><span class="n">RETURN</span><span class="p">)</span> |
| |
| <span class="n">browser</span><span class="o">.</span><span class="n">quit</span><span class="p">()</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="example-2"> |
| <h2>Example 2:<a class="headerlink" href="#example-2" title="Permalink to this headline">¶</a></h2> |
| <p>Selenium WebDriver is often used as a basis for testing web applications. Here is a simple example uisng Python’s standard <a class="reference external" href="http://docs.python.org/3/library/unittest.html">unittest</a> library:</p> |
| <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">unittest</span> |
| |
| <span class="k">class</span> <span class="nc">GoogleTestCase</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span> |
| |
| <span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> |
| <span class="bp">self</span><span class="o">.</span><span class="n">browser</span> <span class="o">=</span> <span class="n">webdriver</span><span class="o">.</span><span class="n">Firefox</span><span class="p">()</span> |
| <span class="bp">self</span><span class="o">.</span><span class="n">addCleanup</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">browser</span><span class="o">.</span><span class="n">quit</span><span class="p">)</span> |
| |
| <span class="k">def</span> <span class="nf">testPageTitle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> |
| <span class="bp">self</span><span class="o">.</span><span class="n">browser</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'http://www.google.com'</span><span class="p">)</span> |
| <span class="bp">self</span><span class="o">.</span><span class="n">assertIn</span><span class="p">(</span><span class="s">'Google'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">browser</span><span class="o">.</span><span class="n">title</span><span class="p">)</span> |
| |
| <span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span> |
| <span class="n">unittest</span><span class="o">.</span><span class="n">main</span><span class="p">(</span><span class="n">verbosity</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="selenium-server-optional"> |
| <h2>Selenium Server (optional)<a class="headerlink" href="#selenium-server-optional" title="Permalink to this headline">¶</a></h2> |
| <p>For normal WebDriver scripts (non-Remote), the Java server is not needed.</p> |
| <p>However, to use Selenium Webdriver Remote or the legacy Selenium API (Selenium-RC), you need to also run the Selenium server. The server requires a Java Runtime Environment (JRE).</p> |
| <p>Download the server separately, from: <a class="reference external" href="http://selenium-release.storage.googleapis.com/2.40/selenium-server-standalone-2.40.0.jar">http://selenium-release.storage.googleapis.com/2.40/selenium-server-standalone-2.40.0.jar</a></p> |
| <p>Run the server from the command line:</p> |
| <div class="highlight-python"><pre>java -jar selenium-server-standalone-2.40.0.jar</pre> |
| </div> |
| <p>Then run your Python client scripts.</p> |
| </div> |
| <div class="section" id="use-the-source-luke"> |
| <h2>Use The Source Luke!<a class="headerlink" href="#use-the-source-luke" title="Permalink to this headline">¶</a></h2> |
| <p>View source code online:</p> |
| <table border="1" class="docutils"> |
| <colgroup> |
| <col width="17%" /> |
| <col width="83%" /> |
| </colgroup> |
| <tbody valign="top"> |
| <tr class="row-odd"><td>official:</td> |
| <td><a class="reference external" href="https://code.google.com/p/selenium/source/browse/py">https://code.google.com/p/selenium/source/browse/py</a></td> |
| </tr> |
| <tr class="row-even"><td>mirror:</td> |
| <td><a class="reference external" href="https://github.com/SeleniumHQ/selenium/tree/master/py">https://github.com/SeleniumHQ/selenium/tree/master/py</a></td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| |
| |
| </div> |
| </div> |
| </div> |
| <div class="sphinxsidebar"> |
| <div class="sphinxsidebarwrapper"> |
| <h3><a href="#">Table Of Contents</a></h3> |
| <ul> |
| <li><a class="reference internal" href="#">Selenium Client Driver</a><ul> |
| <li><a class="reference internal" href="#introduction">Introduction</a></li> |
| <li><a class="reference internal" href="#supported-python-versions">Supported Python Versions</a></li> |
| <li><a class="reference internal" href="#installing">Installing</a></li> |
| <li><a class="reference internal" href="#example-0">Example 0:</a></li> |
| <li><a class="reference internal" href="#example-1">Example 1:</a></li> |
| <li><a class="reference internal" href="#example-2">Example 2:</a></li> |
| <li><a class="reference internal" href="#selenium-server-optional">Selenium Server (optional)</a></li> |
| <li><a class="reference internal" href="#use-the-source-luke">Use The Source Luke!</a></li> |
| </ul> |
| </li> |
| </ul> |
| |
| <h3>This Page</h3> |
| <ul class="this-page-menu"> |
| <li><a href="_sources/index.txt" |
| rel="nofollow">Show Source</a></li> |
| </ul> |
| <div id="searchbox" style="display: none"> |
| <h3>Quick search</h3> |
| <form class="search" action="search.html" method="get"> |
| <input type="text" name="q" /> |
| <input type="submit" value="Go" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| <p class="searchtip" style="font-size: 90%"> |
| Enter search terms or a module, class or function name. |
| </p> |
| </div> |
| <script type="text/javascript">$('#searchbox').show(0);</script> |
| </div> |
| </div> |
| <div class="clearer"></div> |
| </div> |
| <div class="related"> |
| <h3>Navigation</h3> |
| <ul> |
| <li class="right" style="margin-right: 10px"> |
| <a href="genindex.html" title="General Index" |
| >index</a></li> |
| <li class="right" > |
| <a href="py-modindex.html" title="Python Module Index" |
| >modules</a> |</li> |
| <li><a href="#">Selenium 2.0 documentation</a> »</li> |
| </ul> |
| </div> |
| <div class="footer"> |
| © Copyright 2011, plightbo, simon.m.stewart, hbchai, jrhuggins, et al.. |
| </div> |
| </body> |
| </html> |