selenium 网页搜索Demo

#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest

class PythonSearch(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Safari()
    def test_search(self):
        driver = self.driver
        driver.get("http://www.python.org")
        elem = driver.find_element_by_name("q")
        elem.send_keys("pyhton")

        elem.send_keys(Keys.RETURN)
        assert "No results found." not in driver.page_source
    def tearDown(self):
        self.driver.quit()
if __name__ == "__main__":
    unittest.main()

Leave a Reply

Your email address will not be published.