Object
The main class through which you control the browser.
@see Find @see Navigation @see TargetLocator @see Options
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
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
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 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
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 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
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
# 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
@return [Options] @see Options
# File common/src/rb/lib/selenium/webdriver/driver.rb, line 97 def manage @manage ||= WebDriver::Options.new(self) end
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 the browser
# File common/src/rb/lib/selenium/webdriver/driver.rb, line 163 def quit bridge.quit end
driver.script(‘function() { … };’)
@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
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
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
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
Get the current window handle
@return [String]
# File common/src/rb/lib/selenium/webdriver/driver.rb, line 192 def window_handle bridge.getCurrentWindowHandle end
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
Generated with the Darkfish Rdoc Generator 2.