首页 > 解决方案 > 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 秒才能检测到窗口关闭。知道为什么速度会有这样的差异吗?

标签: pythonselenium

解决方案


推荐阅读