标签:amp import htm sim close testing elf unit span
1 from selenium import webdriver 2 3 browser = webdriver.Chrome() 4 browser.get(‘http://baidu.com‘)
1 from selenium import webdriver 2 from selenium.webdriver.common.keys import Keys 3 4 browser = webdriver.Chrome() 5 browser.get(‘http://www.baidu.com‘) 6 7 elem = browser.find_element_by_id(‘kw‘) 8 9 #Keys.RETURN是导入第二个模块的用法 10 elem.send_keys(‘python‘+Keys.RETURN) 11 12 browser.quit()
Selenium WebDriver is often used as a basis for testing web applications. Here is a simple example uisng Python’s standard unittest library:
1 import unittest 2 from selenium import webdriver 3 from selenium.webdriver.common.keys import Keys 4 5 #该测试类继承自 unittest.TestCase 6 class PythonOrgSearch(unittest.TestCase): 7 8 def setUp(self): 9 self.driver = webdriver.Chrome() 10 11 def test_search(self): 12 driver = self.driver 13 driver.get("http://www.taobao.com") 14 elem = driver.find_element_by_id("q") 15 elem.send_keys("python") 16 elem.send_keys(Keys.RETURN) 17 assert "No results found." not in driver.page_source 18 19 20 def tearDown(self): 21 self.driver.close() 22 23 if __name__ == "__main__": 24 unittest.main()
标签:amp import htm sim close testing elf unit span
原文地址:https://www.cnblogs.com/sineik/p/9032898.html