class Webdriver::Session

Attributes

id[R]

Public Class Methods

new(json, connection) click to toggle source
# File lib/webdriver/session.rb, line 5
def initialize(json, connection)
  @id = json.dig "id"
  @connection = Webdriver::PrefixConnection.new "session/#{@id}", connection
end

Public Instance Methods

accept_alert!() click to toggle source
# File lib/webdriver/session.rb, line 117
def accept_alert!
  @connection.post "alert/accept"
  self
end
active_element() click to toggle source

when moving with tab, or clicked

# File lib/webdriver/session.rb, line 252
def active_element
  el = @connection.get "element/active"
  Webdriver::Element.new el["ELEMENT"], @connection
end
alert_text() click to toggle source
# File lib/webdriver/session.rb, line 122
def alert_text
  @connection.get "alert/text"
end
application_cache_status() click to toggle source
# File lib/webdriver/session.rb, line 85
def application_cache_status
  @connection.get "application_cache/status"
end
back!() click to toggle source
# File lib/webdriver/session.rb, line 157
def back!
  @connection.post "back"
  self
end
chromium_heap_snapshot() click to toggle source
# File lib/webdriver/session.rb, line 94
def chromium_heap_snapshot
  @connection.get "chromium/heap_snapshot"
end
chromium_network_conditions() click to toggle source
# File lib/webdriver/session.rb, line 98
def chromium_network_conditions
  @connection.get "chromium/network_conditions"
end
chromium_network_conditions!(conditions) click to toggle source
# File lib/webdriver/session.rb, line 102
def chromium_network_conditions! conditions
  @connection.post "chromium/network_conditions", {}, conditions
  self
end
chromium_network_conditions_delete!() click to toggle source
# File lib/webdriver/session.rb, line 107
def chromium_network_conditions_delete!
  @connection.delete "chromium/network_conditions"
  self
end
chromium_send_command_and_get_result!(opts) click to toggle source
# File lib/webdriver/session.rb, line 20
def chromium_send_command_and_get_result! opts
  # cmd: "Browser.getVersion", params: {}
  @connection.post "chromium/send_command_and_get_result", {}, opts
end
cookies() click to toggle source
# File lib/webdriver/session.rb, line 176
def cookies
  resp = @connection.get "cookie"

  resp.map { |el| Webdriver::Cookie.new el["name"], @connection }
end
cookies_delete!() click to toggle source
# File lib/webdriver/session.rb, line 182
def cookies_delete!
  @connection.delete "cookie"
  self
end
delete!() click to toggle source
# File lib/webdriver/session.rb, line 10
def delete!
  @connection.delete
  self
end
dismiss_alert!() click to toggle source
# File lib/webdriver/session.rb, line 112
def dismiss_alert!
  @connection.post "alert/dismiss"
  self
end
element(using, value) click to toggle source
# File lib/webdriver/session.rb, line 257
def element using, value
  el = @connection.post "element", {}, {
    using: using,
    value: value
  }
  Webdriver::Element.new el["ELEMENT"], @connection
end
elements(using, value) click to toggle source
# File lib/webdriver/session.rb, line 265
def elements using, value
  resp = @connection.post "elements", {}, {
    using: using,
    value: value
  }
  resp.map { |el| Webdriver::Element.new el["ELEMENT"], @connection }
end
execute_sync!(script, args=[]) click to toggle source

TODO: hangs def execute_async! script, args=[]

@connection.post "execute/async", {}, {
  script: script,
  args: args
}

end

# File lib/webdriver/session.rb, line 210
def execute_sync! script, args=[]
  resp = @connection.post "execute/sync", {}, {
    script: script,
    args: args
  }

  value = if resp.is_a?(Hash) && resp["ELEMENT"]
    begin
      el = Webdriver::Element.new resp["ELEMENT"], @connection
      el.tag
      el
    rescue
      resp
    end
  elsif resp.is_a?(Array)
    begin
      resp.map do |r|
        el = Webdriver::Element.new r["ELEMENT"], @connection
        el.tag
        el
      end
    rescue
      resp
    end
  else
    resp
  end
end
forward!() click to toggle source
# File lib/webdriver/session.rb, line 162
def forward!
  @connection.post "forward"
  self
end
frame!(name) click to toggle source

iframe id

# File lib/webdriver/session.rb, line 134
def frame! name
  @connection.post "frame", {}, {
    id: name
  }
  self
end
is_loading?() click to toggle source
# File lib/webdriver/session.rb, line 25
def is_loading?
  @connection.get "is_loading"
end
keys=(opts) click to toggle source

www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/Keys enter “ue007”

# File lib/webdriver/session.rb, line 40
def keys= opts
  @connection.post "keys", {}, opts
end
location() click to toggle source
# File lib/webdriver/session.rb, line 49
def location
  @connection.get "location"
end
location!(opts) click to toggle source
# File lib/webdriver/session.rb, line 53
def location! opts
  #{location: {latitude: 20, longitude:20}}
  @connection.post "location", {}, opts
end
log(type) click to toggle source
# File lib/webdriver/session.rb, line 79
def log type
  @connection.post "log", {}, {
    type: type
  }
end
log_types() click to toggle source
# File lib/webdriver/session.rb, line 75
def log_types
  @connection.get "log/types"
end
moveto!(opts) click to toggle source
# File lib/webdriver/session.rb, line 44
def moveto! opts
  # xoffset, yoffset, element
  @connection.post "moveto", {}, opts
end
page_freeze!() click to toggle source
# File lib/webdriver/session.rb, line 29
def page_freeze!
  @connection.post "goog/page/freeze"
end
page_resume!() click to toggle source
# File lib/webdriver/session.rb, line 33
def page_resume!
  # needs window min/max / timeout to resume
  @connection.post "goog/page/resume"
end
parent_frame!() click to toggle source
# File lib/webdriver/session.rb, line 141
def parent_frame!
  @connection.post "frame/parent", {}, {}
  self
end
print!(opts) click to toggle source
refresh!() click to toggle source
# File lib/webdriver/session.rb, line 167
def refresh!
  @connection.post "refresh"
  self
end
reporting_generate_test_report!(opts) click to toggle source
# File lib/webdriver/session.rb, line 58
def reporting_generate_test_report! opts
  @connection.post "reporting/generate_test_report", {}, opts
end
screenshot() click to toggle source
# File lib/webdriver/session.rb, line 243
def screenshot
  @connection.get "screenshot"
end
screenshot_full() click to toggle source
# File lib/webdriver/session.rb, line 247
def screenshot_full
  @connection.get "screenshot/full"
end
source() click to toggle source

not implemented in chromedriver

# File lib/webdriver/session.rb, line 90
def source
  @connection.get "source"
end
timeouts() click to toggle source
# File lib/webdriver/session.rb, line 62
def timeouts
  @connection.get "timeouts"
end
timeouts!(opts) click to toggle source
# File lib/webdriver/session.rb, line 66
def timeouts! opts
  @connection.post "timeouts", {}, opts
  self
end
timeouts_async_script!(opts) click to toggle source
# File lib/webdriver/session.rb, line 71
def timeouts_async_script! opts
  @connection.post "timeouts/async_script", {}, opts
end
title() click to toggle source
# File lib/webdriver/session.rb, line 172
def title
  @connection.get "title"
end
url() click to toggle source
# File lib/webdriver/session.rb, line 153
def url
  @connection.get "url"
end
url!(url) click to toggle source
# File lib/webdriver/session.rb, line 146
def url! url
  @connection.post "url", {}, {
    url: url
  }
  self
end
windows() click to toggle source
# File lib/webdriver/session.rb, line 15
def windows
  value = @connection.get "window/handles"
  value.map { |id| Webdriver::Window.new id, @connection }
end