2011-12-20 80 views
7

有没有一种方法来设置Selenium Webdriver在ruby中的执行速度。setSpeed在Selenium WebDriver使用Ruby

在Perl中硒1(RC)有$sel->set_speed("500");

但由于硒RC的一些限制,我不得不转移到硒的webdriver,不得不开始使用Ruby和我找不到的功能相同。

在C#和Perl中设置速度的参数,而不是在Ruby中,在某处选择“Slow”,“Medium”和“Fast”选项。

注 - 我有这个@driver.manage.timeouts.implicit_wait = 30超时设置,但我正在寻找执行速度。

回答

10

前段时间,所有语言绑定都不赞成在WebDriver中设置执行速度的方法。不再可以修改正在运行的WebDriver代码的执行速度。

+0

那么最好的解决问题的方法是点击一个链接 - 一个弹出窗口,我需要将密钥发送到该弹出框中的文本框。弹出式窗口有时需要较长时间才能加载,因此,即使它出现,该文本框ID的find_element也会失败。我认为搜索元素ID的尝试立即开始,即使弹出窗口在30秒之前加载(我的显式超时),脚本也会失败。 – Amey 2011-12-22 16:21:48

+1

你需要某种明确的等待例程;隐含的等待可能无助于你。在项目直接支持的语言(Java,.NET,Ruby,Python)中,这可以使用WebDriverWait类(或其等价物)来完成。此外,答案取决于“弹出”的含义。这是一个新的浏览器窗口吗?如果是这样,您需要使用driver.switch_to.window()将焦点放在正确的上下文中。如果它是由诸如jQuery之类的JavaScript小部件框架创建的“弹出式窗口”,则在等待例程中使用find_element。 – JimEvans 2011-12-22 18:15:48

+0

因此它弹出一个新窗口,linkedin登录授权更准确。我通过使用handles = @ driver.window_handles @ driver.switch_to.window(handles [1])将控制权转移到新窗口,但是会发生什么......弹出窗口可能会像第二个或两个实际上“弹出”,在此期间切换到窗口失败,并且所有步骤显然都失败。我目前已经放置了... 2秒的睡眠时间(点击链接并等待切换到新窗口)。但我相信有更好的方法。 – Amey 2011-12-22 19:08:10

0

按照http://selenium.googlecode.com/svn/tags/selenium-2.10.0/rb/lib/selenium/client/idiomatic.rb中有2种方法Selenium.Client.Idiomatic模块:

# Get execution delay in milliseconds, i.e. a pause delay following 
    # each selenium operation. By default, there is no such delay 
    # (value is 0). 
    def execution_delay 
    string_command "getSpeed" 
    end 

    # Set the execution delay in milliseconds, i.e. a pause delay following 
    # each selenium operation. By default, there is no such delay. 
    # 
    # Setting an execution can be useful to troubleshoot or capture videos 
    def execution_delay=(delay_in_milliseconds) 
    remote_control_command "setSpeed", [delay_in_milliseconds] 
    end 

我想这会有所帮助。

+1

不能工作,这些功能是Selenium Client Idiomatic模块的一部分,它不包含在Webdriver模块中?我认为。 – Amey 2011-12-21 16:45:12

+0

这是我得到的错误'NoMethodError:未定义的方法'execution_delay'为#' – Amey 2011-12-21 16:46:46