exception - 如何在 Playwright-python 中处理 wait_for_selector 函数的 TimeoutError?
问题描述
我想用它Except TimeoutError
来处理超时问题。但是脚本总是给我一个 TimeoutError,而不是按我的计划打印一条消息。
这是我的代码:
try:
await page.wait_for_selector("#winiframe_main", timeout=10000, state='detached')
print("The frame is detached.")
except TimeoutError:
print("The frame is not detached")
我的代码有什么问题吗?
解决方案
您必须导入TimeoutError
fromplaywright
才能捕获此异常:
from playwright.async_api import async_playwright, TimeoutError
推荐阅读
- python - 我可以用 Amazon Cognito 替换 django 管理面板登录代码吗?
- bash - 用于查找文件中缺少的数字的 Shell 脚本
- audio - 使用 BSP 库在 stm32f769i-Discovery 上进行录音时出现问题
- swift - Flutter iOS 插件中没有调用“handle”函数
- json - 是否可以通过 Jira REST API 在 JQL 中传递多个参数?
- junit - 在junit测试和spring boot中为模型创建可重用的模拟
- oracle - Kafka Connect 同一个插件的 JDBC Source 和 Sink Connector 部分
- ldap - Citrix Netscaler 显示 LDAP 身份验证失败(“错误:'10.0.1.4' 是有效的 LDAP 服务器。未提供有效凭据)
- python-3.x - 变化通货膨胀因子
- sql - 如何根据唯一 ID 将列拆分为两列?