如何在Python中为Selenium Webdriver设置脚本超时?

7 投票
1 回答
6250 浏览
提问于 2025-04-18 03:50

在Java的Webdriver.Timeouts中,有三种超时函数:

  1. 隐式等待(implicitlyWait)
  2. 页面加载超时(pageLoadTimeout)
  3. 脚本超时(setScriptTimeout)

我想找找第三个在Python中的对应函数,但没找到。以下是前两个在Python中的对应写法:

  1. implicitly_wait(10)
  2. set_page_load_timeout(20)

1 个回答

10

这是你在找的东西吗:

set_script_timeout(time_to_wait)

    Set the amount of time that the script should wait during an
        execute_async_script call before throwing an error.

    Args :  

        time_to_wait: The amount of time to wait (in seconds)

    Usage : 

    driver.set_script_timeout(30)

参考 - set_script_timeout

撰写回答