python - python selenium慢窗口关闭检测
问题描述
我使用简单的脚本来检测硒浏览器窗口何时关闭。
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
import time
driver = webdriver.Chrome()
driver.get("https://google.com")
while True:
try:
driver.title
print('ok')
except WebDriverException:
print('closed')
break
time.sleep(1)
该代码按预期工作,但是在具有 selenium 1.25.9 和 python 3.8.2 的 Linux 机器上对关闭窗口的检测是立即的,而在 Windows 10 机器(selenium 1.25.8,python 3.8.5)上需要 10-15 秒才能检测到窗口关闭。知道为什么速度会有这样的差异吗?
解决方案
推荐阅读
- python - 如何在python中存储/检索/使用稀疏的3D矩阵
- go - 如何将切片转换为固定长度的切片并返回
- xml - XML 模式如何允许元素的简单内容或复杂类型?
- python - QisKit:状态向量的差异/可视化没有差异
- sql-server - 如何在 SQL Server 中查询 XML 列?
- assembly - 如何在 ARM64 汇编代码中分配可写内存?
- strapi - 有没有办法获得 Strapi CMS 内容类型的结构?
- javascript - 如何使用看起来像命名组的正则表达式分隔符?
- r - 如何在处理 csv 文件后添加带有统计信息的部分
- keyboard - Notepad++ 复制/粘贴不再起作用