【selenium踩坑系列】隐式等待 报错value must be a non-negative integer
运行以下代码时,使用selenium的隐式等待出现报错:
class TestCase_login():
@classmethod
def setup_class(cls):
cls.driver = browser('chrome')
# 隐式等待10秒
cls.driver.implicitly_wait(10)
报错信息如下
selenium.common.exceptions.WebDriverException: Message: invalid argument: value must be a non-negative integer
疑惑了一会为什么会报“值必须是一个非负整数”这种错,百度后找到解决方法,是selenium版本的问题,我的版本是selenium 3.5,卸载selenium 3.5,重新下载selenium-3.141.0之后,运行程序,问题解决。
安装命令:
pip install selenium==3.141.0
以下代码可测试隐式等待是否生效
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from time import ctime
driver = webdriver.Chrome()
# implicitly_wait是隐式等待
# 判断某元素,如果超过10秒未发现,则抛出异常
# 如果在10秒内发现,则对该元素进行操作
driver.implicitly_wait(10)
driver.get("https://www.baidu.com")
try:
print(ctime())
driver.find_element_by_xpath("//*[@id='kww']").send_keys('Bela')
driver.find_element_by_xpath("//*[@id='su']").click()
except NoSuchElementException as e:
print(e)
finally:
print(ctime())
本文来自博客园,作者:是小鱼呀,转载请注明原文链接:https://www.cnblogs.com/sophia12138/p/15969727.html