在selenium python中,如何无限期地等待一个元素被单击?

2024-09-30 12:22:37 发布

您现在位置:Python中文网/ 问答频道 /正文

此功能在Puppeter中可用,它允许将0作为无限超时传递。但硒中没有同样的成分。你们知道有什么自定义函数吗

另外,我需要这个函数,因为我想在我的服务器上测试一些东西,超时可以是可变的,有时需要30秒,有时需要30米


Tags: 函数功能服务器成分puppeter
1条回答
网友
1楼 · 发布于 2024-09-30 12:22:37

Selenium中没有无限等待的概念。因为这不是等待无限时间(1分钟、1小时、1天、1个月、1年……等等)的理想情况

特定条件应在特定时间内完成。所以,您可以做的一件事是提供最大阈值等待时间。Selenium将持续检查元素是否可单击,直到达到最大阈值

根据Selenium文件:

ExplicitWait allow your code to halt program execution, or freeze the thread, until the condition you pass it resolves. The condition is called with a certain frequency until the timeout of the wait is elapsed. This means that for as long as the condition returns a falsy value, it will keep trying and waiting.

相关问题 更多 >

    热门问题