标签:select 解决 com res tor support 定位 定位元素 问答
脚本问答题导致测试用例不稳定,DOM还没加载出元素就执行了脚本导致报回错,这种只要使用答显式等待大部分都能解决。
###############
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from time import sleep # 实例化浏览器 driver = webdriver.Firefox() driver.get("https://www.baidu.com") element = (By.CSS_SELECTOR,‘#kw‘) WebDriverWait(driver,10).until(EC.presence_of_element_located(element)).send_keys(‘admin‘) sleep(2) driver.quit() 可以分开写: driver = webdriver.Firefox() driver.get("https://www.baidu.com") element = (By.CSS_SELECTOR,‘#kw‘) wait = WebDriverWait(driver,10) element = wait.until(EC.presence_of_element_located(element)) element.send_keys(‘admin‘) sleep(2) driver.quit() 如果找不到元素,会报出一个异常,
################
标签:select 解决 com res tor support 定位 定位元素 问答
原文地址:https://www.cnblogs.com/andy0816/p/12918260.html