Class: Webdriver::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/webdriver/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, connection) ⇒ Session

Returns a new instance of Session.



5
6
7
8
# File 'lib/webdriver/session.rb', line 5

def initialize(json, connection)
  @id = json.dig "id"
  @connection = Webdriver::PrefixConnection.new "session/#{@id}", connection
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/webdriver/session.rb', line 3

def id
  @id
end

Instance Method Details

#accept_alert!Object



30
31
32
33
# File 'lib/webdriver/session.rb', line 30

def accept_alert!
  @connection.post "alert/accept"
  self
end

#active_elementObject

when moving with tab, or clicked



162
163
164
165
# File 'lib/webdriver/session.rb', line 162

def active_element
  el = @connection.get "element/active"
  Webdriver::Element.new el["ELEMENT"], @connection
end

#alert_textObject



35
36
37
# File 'lib/webdriver/session.rb', line 35

def alert_text
  @connection.get "alert/text"
end

#back!Object



70
71
72
73
# File 'lib/webdriver/session.rb', line 70

def back!
  @connection.post "back"
  self
end


100
101
102
103
# File 'lib/webdriver/session.rb', line 100

def cookie name
  resp = @connection.get File.join("cookie",name)
  Webdriver::Element.new resp["name"], @connection
end

#cookiesObject



89
90
91
92
93
# File 'lib/webdriver/session.rb', line 89

def cookies
  resp = @connection.get "cookie"

  resp.map { |el| Webdriver::Cookie.new el["name"], @connection }
end

#cookies_delete!Object



95
96
97
98
# File 'lib/webdriver/session.rb', line 95

def cookies_delete!
  @connection.delete "cookie"
  self
end

#delete!Object



10
11
12
13
# File 'lib/webdriver/session.rb', line 10

def delete!
  @connection.delete
  self
end

#dismiss_alert!Object

not implemented in chromedriver def source

@connection.post "source"

end



25
26
27
28
# File 'lib/webdriver/session.rb', line 25

def dismiss_alert!
  @connection.post "alert/dismiss"
  self
end

#element(using, value) ⇒ Object



167
168
169
170
171
172
173
# File 'lib/webdriver/session.rb', line 167

def element using, value
  el = @connection.post "element", {}, {
    using: using,
    value: value
  }
  Webdriver::Element.new el["ELEMENT"], @connection
end

#elements(using, value) ⇒ Object



175
176
177
178
179
180
181
# File 'lib/webdriver/session.rb', line 175

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 = []) ⇒ Object

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

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

end



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/webdriver/session.rb', line 123

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!Object



75
76
77
78
# File 'lib/webdriver/session.rb', line 75

def forward!
  @connection.post "forward"
  self
end

#frame!(name) ⇒ Object

iframe id



47
48
49
50
51
52
# File 'lib/webdriver/session.rb', line 47

def frame! name
  @connection.post "frame", {}, {
    id: name
  }
  self
end

#parent_frame!Object



54
55
56
57
# File 'lib/webdriver/session.rb', line 54

def parent_frame!
  @connection.post "frame/parent", {}, {}
  self
end

#refresh!Object



80
81
82
83
# File 'lib/webdriver/session.rb', line 80

def refresh!
  @connection.post "refresh"
  self
end

#screenshotObject

not implemented in chromedriver def print!

@connection.post "print"

end



157
158
159
# File 'lib/webdriver/session.rb', line 157

def screenshot
  @connection.get "screenshot"
end

#titleObject



85
86
87
# File 'lib/webdriver/session.rb', line 85

def title
  @connection.get "title"
end

#urlObject



66
67
68
# File 'lib/webdriver/session.rb', line 66

def url
  @connection.get "url"
end

#url!(url) ⇒ Object



59
60
61
62
63
64
# File 'lib/webdriver/session.rb', line 59

def url! url
  @connection.post "url", {}, {
    url: url
  }
  self
end

#windowsObject



15
16
17
18
# File 'lib/webdriver/session.rb', line 15

def windows
  value = @connection.get "window/handles"
  value.map { |id| Webdriver::Window.new id, @connection }
end