Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no such thing as Python webdriver. <a href="http://seleniumhq.org/docs/03_webdriver.html">Webdriver</a> is a component for driving webpages. It has been integrated to the Selenium 2. Natively it works in Java, but there are bindings available for many languages, including <a href="http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html">Python</a>. </p> <p>Here's an annotated example from the webdriver documentation modified a little. For creating a unittest, make a test class that inherits the class TestCase provided by unittest module.</p> <pre><code>#!/usr/bin/python from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0 import unittest class GoogleTest(unittest.TestCase): def test_basic_search(self): # Create a new instance of the Firefox driver driver = webdriver.Firefox() driver.implicitly_wait(10) # go to the google home page driver.get("http://www.google.com") # find the element that's name attribute is q (the google search box) inputElement = driver.find_element_by_name("q") # type in the search inputElement.send_keys("Cheese!") # submit the form (although google automatically searches # now without submitting) inputElement.submit() # the page is ajaxy so the title is originally this: original_title = driver.title try: # we have to wait for the page to refresh, the last thing # that seems to be updated is the title WebDriverWait(driver, 10).until(lambda driver : driver.title != original_title) self.assertIn("cheese!", driver.title.lower()) # You should see "cheese! - Google Search" print driver.title finally: driver.quit() if __name__ == '__main__': unittest.main() </code></pre> <p>One nice thing about webdriver is that you can change the driver line to be</p> <pre><code>driver = webdriver.Chrome() driver = webdriver.Firefox() driver = webdriver.Ie() </code></pre> <p>depending on what browsers you need to test. In addition to <a href="http://code.google.com/p/selenium/wiki/ChromeDriver">ChromeDriver</a>, <a href="http://code.google.com/p/selenium/wiki/FirefoxDriver">FirefoxDriver</a> or <a href="http://code.google.com/p/selenium/wiki/InternetExplorerDriver">InternetExplorerDriver</a> there's also <a href="http://code.google.com/p/selenium/wiki/HtmlUnitDriver">HtmlUnitDriver</a> which is most lightweight and can run headless (but may run some javascript differently than browsers), <a href="http://code.google.com/p/selenium/wiki/RemoteWebDriver">RemoteWebDriver</a> which allows running tests on remote machines and in parallel, and many others (iPhone, Android, Safari, Opera).</p> <p>Running it can be done as running any python script. Either just with:</p> <pre><code>python &lt;script_name.py&gt; </code></pre> <p>or including the interpreter name on the first line like <code>!#/usr/bin/python</code> above. The last two lines </p> <pre><code>if __name__ == '__main__': unittest.main() </code></pre> <p>make the script run the test when this file is run directly like <code>./selenium_test.py</code>. It is also possible to collect test cases automatically from multiple files and run them together (see unittest documentation). Another way running tests in some module or some individual test is</p> <pre><code>python -m unittest selenium_test.GoogleTest </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload