7

Is there a way to set the Selenium Webdriver execution speed in ruby.

In perl for selenium 1(RC) there was $sel->set_speed("500");

But due to some constraints of Selenium RC, I had to shift to Selenium Webdriver and had to start using Ruby, and I cannot find the function for the same.

Read somewhere the options "Slow", "Medium" and "Fast" as arguments to set speed in C# and Perl, but not in Ruby.

Note - I do have timeouts set with this @driver.manage.timeouts.implicit_wait = 30 but i am looking for execution speed.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Amey
  • 8,470
  • 9
  • 44
  • 63

2 Answers2

10

The methods to set the execution speed in WebDriver were deprecated for all language bindings some time ago. It is no longer possible to modify the execution speed of the running WebDriver code.

JimEvans
  • 27,201
  • 7
  • 83
  • 108
  • So whats the best way to resolve an issue, where on clicking a link- a popup opens, and I need to send keys to a textbox in that popup. The popup sometimes takes longer to load, due to which the find_element of that textbox id fails even though it does appear. I think the attempt to search the element id starts immediately and even though the popup loads well before 30 seconds(my explicit timeout), the scripts fails. – Amey Dec 22 '11 at 16:21
  • 1
    You need some sort of explicit wait routine; implicit waits may not help you here. In the languages supported directly by the project (Java, .NET, Ruby, Python), this can be accomplished using the `WebDriverWait` class (or its equivalent). Also, the answer depends a little on what you mean by "popup". Is it a new browser window? If so, you'll need to use driver.switch_to.window() to put your focus in the correct context. If it's a "popup" created by, say, a JavaScript widget framework like jQuery or similar, your find_element in your wait routine. – JimEvans Dec 22 '11 at 18:15
  • So its a new window popup, a linkedin Login authorization to be more accurate. And i do shift controls to the new window, by using handles = @driver.window_handles @driver.switch_to.window(handles[1])... but what happens is.. the popup takes may be like a second or two to actually "pop-up" during which the switching to window fails, and all steps there on obviously fail. I currently have put in place.. a sleep of 2 seconds (between clicking the link and waiting to switch to the new window). But I am sure there is a better way. – Amey Dec 22 '11 at 19:08
  • 3
    Yes, there is. You're in Ruby, so you'll want to use a `Selenium::WebDriver::Wait` object, and wait for @driver.window_handles.size to be > 1. Then you can proceed forward and switch to the new window. You can see an example of this in the [project wiki](http://code.google.com/p/selenium/wiki/RubyBindings). Keep in mind, however, that the handles returned by driver.window_handles are not guaranteed to be in the order they were opened for every browser, so you can't necessarily rely on just taking driver.window_handles[1] and expecting that to be the new window handle. – JimEvans Dec 22 '11 at 21:52
0

According to the http://selenium.googlecode.com/svn/tags/selenium-2.10.0/rb/lib/selenium/client/idiomatic.rb in there are 2 methods Selenium.Client.Idiomatic module:

  # 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

I suppose this will help.

VMykyt
  • 1,589
  • 12
  • 17
  • 1
    Nope that does not work, these functions are part of the Selenium Client Idiomatic module, which is not included in the Webdriver module? I think. – Amey Dec 21 '11 at 16:45
  • This is the error I get btw `NoMethodError: undefined method `execution_delay' for #` – Amey Dec 21 '11 at 16:46