设置了默认等待时间是30s
self.driver = webdriver.PhantomJS()self.driver.implicitly_wait(30)
然后在测试时每次点击链接前会先去查找链接元素是不是存在:
def wait_for(self, content, timeout=10): print("in wait_for: %s" % content) for i in range(timeout): try: #print(datetime.datetime.now()) if self.is_element_present(By.LINK_TEXT, content): break #print(datetime.datetime.now()) except: pass time.sleep(1) else: print("time out") self.fail("time out")
发现链接找不到时程序会等很久才退出, 经调试发现is_element_present是会等待的,等待的时间是implicitly_wait的设置值, 加起来就是40s了