Selenium Webdriver上的超时默认值 [英] The default value of timeouts on selenium webdriver

查看:288
本文介绍了Selenium Webdriver上的超时默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对硒webdriver. ImplicitlyWaitSetPageLoadTimeoutSetScriptTimeout上的超时默认值感兴趣. 因为我想知道,我需要为这些超时设置值吗?或默认值适合selenium webdriver工作. 但是我找不到正确的答案,有人说默认值是0,而另一个人说是30秒.

I am interested in the default value of timeouts on selenium webdriver. ImplicitlyWait, SetPageLoadTimeout and SetScriptTimeout. Because I want to know, Do I need to set a values for those timeouts? or the default value is good for selenium webdriver working. But I cannot find a correct answer, someone say the default value is 0, and other one say it is 30 sec.

推荐答案

这三个超时由Selenium方程的服务器端管理.您的脚本(使用Java,Python,Ruby,C#或其他语言编写)是将命令发送到位于浏览器中的服务器的客户端. (可能会有中介程序将命令中继到浏览器,例如Selenium网格.不幸的是,有时也称为服务器".)

These three timeouts are managed by the server-side of the Selenium equation. Your script, be it in Java, Python, Ruby, C#, or whatever, is a client that sends commands to a server that lives in the browser. (There may be an intermediary that relays commands to the browser, like Selenium grid. Unfortunately, it is also sometimes called a "server".)

从Selenium派生的 WebDriver规范已确定以下值:

The WebDriver specification, which was derived from Selenium has settled on the following values:

  • 对于隐式等待:0秒.这意味着,如果selenium命令没有立即找到一个元素,它将立即报告,而不是等到找到一个元素.

  • For implicit waits: 0 seconds. This means that if a selenium command does not find an element immediately, it reports immediately, rather than wait until an element is found.

对于页面加载:300秒.

For page loads: 300 seconds.

对于脚本超时:30秒.

For script timeouts: 30 seconds.

(规范以毫秒为单位给出值.为了便于阅读,我将其转换为秒.)

(The specification gives the values in milliseconds. I've converted them to seconds for ease of reading.)

硒现在遵循WebDriver规范.

Selenium now follows the WebDriver specification.

但是,Selenium在过去使用了其他值.例如,Firefox驱动程序用于定义其超时,如下所示:

In the past Selenium has used other values for these, however. For instance, the Firefox driver used to define its timeouts like this:

  • 隐式等待超时默认设置为0.这意味着,如果找到元素的命令找不到任何内容,它将不会等待.

  • The implicit wait timeout is set to 0 by default. This means that if a command that finds elements does not find anything, it won't wait.

页面加载超时默认设置为-1.这意味着Selenium将无限期等待页面加载.

The page load timeout is set to -1 by default. This means that Selenium will wait indefinitely for the page to load.

赛富尔

What Saifur found is not the same as the page load timeout. That's a timeout between the Selenium client and the Selenium server, which is not particularly well explained on the page Saifur found.

脚本超时默认设置为0.源代码中的注释说明:

The script timeout is set to 0 by default. A comment in the source code explains:

此会话应等待异步脚本完成执行的时间(以毫秒为单位).如果设置为0,则直到脚本执行后的下一个事件循环,超时才会触发.这将使使用基于0的setTimeout的脚本完成.

The amount of time, in milliseconds, this session should wait for asynchronous scripts to finish executing. If set to 0, then the timeout will not fire until the next event loop after the script is executed. This will give scripts that employ a 0-based setTimeout to finish.

因此,即使将其设置为零,异步脚本仍然可以执行,但是必须在Selenium的超时有机会再次运行之前完成.

So even if it set to zero, an asynchronous script can still execute but it has to complete before Selenium's timeout gets a chance to run again.

这来自Selenium用于Firefox的代码.其他浏览器使用不同的代码库,但至少在某些适合Selenium本身的事情(如这些超时)方面,它们应该表现出一致的行为.因此,其他浏览器的值及其解释也应该相同.

This is from the code that Selenium uses for Firefox. The other browsers use different code bases but they are supposed to behave consistently, at least with regards to things that are proper to Selenium itself, like these timeouts. So the values and their interpretations should be the same for other browsers too.

这篇关于Selenium Webdriver上的超时默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆