Selenium.set_script_timeout(n)的作用是什么?它与driver.set_page_load_超时(n) 是吗?

2024-04-25 07:21:39 发布

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

在PythonSelenium的上下文中,我不太理解driver.set_page_load_timeout(n)与{}之间的确切区别。这两种方法似乎可以互换使用,以设置通过driver.get(URL)加载URL的超时,但有时也一起使用。在

场景1

driver.set_page_load_timeout(5)
website = driver.get(URL)
results = do_magic(driver, URL)

场景2

^{pr2}$

这两种情况有何不同?在一种情况下触发超时,而在另一种情况下不会触发超时?


Tags: 方法urlgetdriverpage场景timeout情况
1条回答
网友
1楼 · 发布于 2024-04-25 07:21:39

根据Selenium Python API Docsset_page_load_timeout(n)set_script_timeout(n)都是timeout方法,用于配置webdriver实例在程序执行期间遵守。在

设置“页面”加载“超时”(等待时间)

^{}设置在引发错误之前等待页面加载完成的时间量,定义为:

    def set_page_load_timeout(self, time_to_wait):
    """
    Set the amount of time to wait for a page load to complete
       before throwing an error.

    :Args:
     - time_to_wait: The amount of time to wait

    :Usage:
        driver.set_page_load_timeout(30)
    """
    try:
        self.execute(Command.SET_TIMEOUTS, {
        'pageLoad': int(float(time_to_wait) * 1000)})
    except WebDriverException:
        self.execute(Command.SET_TIMEOUTS, {
        'ms': float(time_to_wait) * 1000,
        'type': 'page load'})

在这里您可以找到关于^{}的详细讨论

设置“脚本”超时(从“时间”到“等待时间”)

^{}设置在抛出错误之前,^{}Javascript/AJAX调用)期间脚本应等待的时间量,其定义如下:

^{pr2}$

相关问题 更多 >

    热门问题