<p>你看过<a href="http://code.google.com/p/selenium/wiki/PythonBindings" rel="noreferrer"><em>python bindings for WebDriver</em></a>的说明了吗?</p>
<p><a href="http://code.google.com/p/selenium/source/browse/trunk/py/test/selenium/webdriver/common/example2.py" rel="noreferrer">^{<cd1>}</a>很清楚,虽然不是代码的直接翻译:</p>
<pre><code>import unittest
from google_one_box import GoogleOneBox
from selenium.firefox.webdriver import WebDriver
class ExampleTest2(unittest.TestCase):
"""This example shows how to use the page object pattern.
For more information about this pattern, see:
http://code.google.com/p/webdriver/wiki/PageObjects
"""
def setUp(self):
self._driver = WebDriver()
def tearDown(self):
self._driver.quit()
def testSearch(self):
google = GoogleOneBox(self._driver, "http://www.google.com")
res = google.search_for("cheese")
self.assertTrue(res.link_contains_match_for("Wikipedia"))
if __name__ == "__main__":
unittest.main()
</code></pre>
<p>一个测试模块<a href="http://code.google.com/p/selenium/source/browse/trunk/py/test/selenium/webdriver/common/google_one_box.py" rel="noreferrer">GoogleOneBox</a>为一个有google搜索栏的页面建模
(url移动了一点)。</p>