Parent

Included Modules

Class/Module Index [+]

Quicksearch

Selenium::WebDriver::Driver

The main class through which you control the browser.

@see Find @see Navigation @see TargetLocator @see Options

Attributes

bridge[R]

Public Class Methods

for(browser, *args) click to toggle source

Create a new Driver instance with the correct bridge for the given browser

@param browser [:ie, :internet_explorer, :remote, :chrome, :firefox, :ff]

the driver type to use

@param *rest

arguments passed to Bridge.new

@return [Driver]

@example

Driver.for :firefox, :profile => "some-profile"
Driver.for :firefox, :profile => Profile.new
Driver.for :remote,  :url => "http://localhost:4444/wd/hub", :desired_capabilities => caps
# File common/src/rb/lib/selenium/webdriver/driver.rb, line 37
def for(browser, *args)
  bridge = case browser
           when :ie, :internet_explorer
             IE::Bridge.new(*args)
           when :remote
             Remote::Bridge.new(*args)
           when :chrome
             Chrome::Bridge.new(*args)
           when :firefox, :ff
             Firefox::Bridge.new(*args)
           else
             raise ArgumentError, "unknown driver: #{browser.inspect}"
           end

   new(bridge)
end
new(bridge) click to toggle source

A new Driver instance with the given bridge

@api private

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 61
def initialize(bridge)
  @bridge = bridge

  # TODO: refactor this away
  unless @bridge.driver_extensions.empty?
    extend(*@bridge.driver_extensions)
  end
end

Public Instance Methods

[](id) click to toggle source

Get the first element matching the given id.

@param [String] id @return [WebDriver::Element]

driver['someElementId'] #=> #<WebDriver::Element:0x1011c3b88>
# File common/src/rb/lib/selenium/webdriver/driver.rb, line 240
def [](id)
  find_element :id, id
end
close() click to toggle source

Close the current window, or the browser if no windows are left.

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 171
def close
  bridge.close
end
current_url() click to toggle source

Get the URL of the current page

@return [String]

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 115
def current_url
  bridge.getCurrentUrl
end
execute_script(script, *args) click to toggle source

Execute the given JavaScript

@param [String] script

JavaScript source to execute

@param [WebDriver::Element,Integer, Float, Boolean, NilClass, String, Array] *args

Arguments will be available in the given script as the 'arguments' array.

@return [WebDriver::Element,Integer,Float,Boolean,NilClass,String,Array]

The value returned from the script.
# File common/src/rb/lib/selenium/webdriver/driver.rb, line 208
def execute_script(script, *args)
  bridge.executeScript(script, *args)
end
Also aliased as: script
get(url) click to toggle source

Opens the specified URL in the browser.

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 105
def get(url)
  navigate.to(url)
end
inspect() click to toggle source
# File common/src/rb/lib/selenium/webdriver/driver.rb, line 70
def inspect
  '#<%s:0x%x browser=%s>' % [self.class, hash*2, bridge.browser.inspect]
end
manage() click to toggle source

@return [Options] @see Options

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 97
def manage
  @manage ||= WebDriver::Options.new(self)
end
page_source() click to toggle source

Get the source of the current page

@return [String]

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 135
def page_source
  bridge.getPageSource
end
quit() click to toggle source

Quit the browser

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 163
def quit
  bridge.quit
end
ref() click to toggle source

for Find

@private

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 251
def ref
  nil
end
script(script, *args) click to toggle source

driver.script(‘function() { … };’)

Alias for: execute_script
switch_to() click to toggle source

@return [TargetLocator] @see TargetLocator

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 88
def switch_to
  @switch_to ||= WebDriver::TargetLocator.new(self)
end
title() click to toggle source

Get the title of the current page

@return [String]

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 125
def title
  bridge.getTitle
end
visible=(bool) click to toggle source

Set the visibility of the browser. Not applicable for all browsers.

@param [Boolean]

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 155
def visible=(bool)
  bridge.setBrowserVisible bool
end
visible?() click to toggle source

Get the visibility of the browser. Not applicable for all browsers.

@return [Boolean]

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 145
def visible?
  bridge.getBrowserVisible
end
window_handle() click to toggle source

Get the current window handle

@return [String]

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 192
def window_handle
  bridge.getCurrentWindowHandle
end
window_handles() click to toggle source

Get the window handles of open browser windows.

@return [Array] @see TargetLocator#window

# File common/src/rb/lib/selenium/webdriver/driver.rb, line 182
def window_handles
  bridge.getWindowHandles
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.