标签:web expect except cat python wss exp bdr expected
Selenium 入门到精通系列
PS:显式等待、隐式等待、强制等待方法
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2019-04-23 16:12:33
# @Author : BenLam
# @Link : https://www.cnblogs.com/BenLam/
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
driver=webdriver.Firefox()
driver.get("http://www.baidu.com")
wait=WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.ID,‘kw‘)))
wait.send_keys("TEST")
driver.find_element_by_id("su").click()
#隐式等待
from selenium.common.exceptions import NoSuchElementException
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
try:
driver.find_element_by_id("kwsssss")
except NoSuchElementException as e:
print(e)
finally:
driver.quit()
#强制等待
driver.get("http://www.baidu.com")
sleep(5)
driver.find_element_by_id("kwsssss")
driver.quit()
标签:web expect except cat python wss exp bdr expected
原文地址:https://www.cnblogs.com/BenLam/p/10758101.html