【selenium踩坑系列】隐式等待 报错value must be a non-negative integer

是小鱼呀·2022-03-05 22:33·830 次阅读

【selenium踩坑系列】隐式等待 报错value must be a non-negative integer

运行以下代码时,使用selenium的隐式等待出现报错:

Copy
class TestCase_login(): @classmethod def setup_class(cls): cls.driver = browser('chrome') # 隐式等待10秒 cls.driver.implicitly_wait(10)

报错信息如下

Copy
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

以下代码可测试隐式等待是否生效

Copy
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())
posted @   是小鱼呀  阅读(830)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示