For instructions on WebDriver in Ruby, see rubywebdriver.
Explicit wait:
wait = Selenium::WebDriver::Wait.new(:timeout => 3)wait.until { driver.find_element(:id => "cheese").displayed? }
Implicit wait:
driver = Selenium::WebDriver.for :firefoxdriver.manage.timeouts.implicit_wait = 3 # seconds
Internal Timeout:
The WebDriver uses the http protocol internally to interact with various drivers. By default, the Net: HTTP protocol in the Ruby standard library has a default timeout of 60 seconds. If you call the Driver to load a page that exceeds 60 seconds, you will see a timeout error from Net: HTTP. You can manually configure the timeout before starting the browser.
client = Selenium::WebDriver::Remote::Http::Default.newclient.timeout = 120 # secondsdriver = Selenium::WebDriver.for(:remote, :http_client => client)
When ruby webdriver starts firefox driver, it loads firebug Extension
See on the official wiki
Adding an extension
It's often useful to have Firebug available in the Firefox instance launched by WebDriver:
profile = Selenium::WebDriver::Firefox::Profile.newprofile.add_extension("/path/to/firebug.xpi")driver = Selenium::WebDriver.for :firefox, :profile => profile
I tried it myself, but every time I was prompted that I could not find firebug. xpi.
Today, I'm free. The problem is solved.
Actually, this is because dr = Selenium: WebDriver. for: ff
When ff is started, a simple profile is initialized, which does not contain the firebug plug-in. That is to say, even if we installed firebug on firefox, it cannot be started, so when we need to use firebug, We need to load a firebug extension.
profile.add_extension("/path/to/firebug.xpi")
For "/path/to/firebug. xpi is firebug. xpi storage path. We can download a firebug online. xpi (corresponding version, my ff is 14, you can use the firebug-1.10.4.xpi, it is best to use a non firefox browser to download, or prompt you to install directly to firefox)
We can directly store firefox. xpi in the path where our script is stored. Both the relative path and absolute path can be used.
An example of Baidu
Require 'selenium-webdriver '# dr = selenium: WebDriver. for: ffprofile = Selenium: WebDriver: Firefox: Profile. newprofile. add_extension ("path/to/firebug-1.10.4.xpi") <font color = "DarkOrchid"> # The firefox-1.10.4.xpi is stored under path/to the same level as the script </font> dr = Selenium :: webDriver. for: firefox,: profile => profiledr. get http://www.baidu.com"
In this way, when we need to view the dom structure, we can directly debug it on the open test page, instead of opening a new firefox to view the dom structure.