python selenium 使用unittest 示例 并等待某个元素示例
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium import webdriver import unittest class TestBaidu(unittest.TestCase): def setUp(self): browser_engine = BrowerEngine(self) self.driver = browser_engine.get_browser() print(browser_engine) print(self.driver) print(browser_engine) def tearDown(self): self.driver.quit() def test_baidu(self): self.driver.get("http://www.baidu.com") element = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.ID, "kw"))) class BrowerEngine: def __init__(self,driver): self.driver = driver brower_type = 'Chrome' def get_browser(self): if self.brower_type == 'Chrome': driver = webdriver.Chrome("D:/AutoConf/bin/chromedriver.exe") elif self.brower_type == 'Firefox': driver = webdriver.Firefox() elif self.brower_type == 'IE': driver = webdriver.Ie() else: driver = webdriver.Chrome return driver if __name__ == '__main__': unittest.main()