selenium-webdriver 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -194,7 +194,14 @@ FirefoxDriver.prototype.getPageSource = function(respond) {
194
194
  */
195
195
  FirefoxDriver.prototype.findElementByXPath_ = function(theDocument, xpath,
196
196
  opt_contextNode) {
197
- var contextNode = opt_contextNode || theDocument;
197
+ if (opt_contextNode) {
198
+ var contextNode = opt_contextNode;
199
+ if (xpath) {
200
+ xpath = Utils.getXPathOfElement(contextNode) + (xpath[0] == "/" ? "" : "/") + xpath;
201
+ }
202
+ } else {
203
+ var contextNode = theDocument;
204
+ }
198
205
  return theDocument.evaluate(xpath, contextNode, null,
199
206
  Components.interfaces.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE, null).
200
207
  singleNodeValue;
@@ -213,7 +220,14 @@ FirefoxDriver.prototype.findElementByXPath_ = function(theDocument, xpath,
213
220
  */
214
221
  FirefoxDriver.prototype.findElementsByXPath_ = function(theDocument, xpath,
215
222
  opt_contextNode) {
216
- var contextNode = opt_contextNode || theDocument;
223
+ if (opt_contextNode) {
224
+ var contextNode = opt_contextNode;
225
+ if (xpath) {
226
+ xpath = Utils.getXPathOfElement(contextNode) + (xpath[0] == "/" ? "" : "/") + xpath;
227
+ }
228
+ } else {
229
+ var contextNode = theDocument;
230
+ }
217
231
  var result = theDocument.evaluate(xpath, contextNode, null,
218
232
  Components.interfaces.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
219
233
  var elements = [];
@@ -1226,3 +1226,28 @@ Utils.wrapResult = function(result, context) {
1226
1226
  return {type: "OTHER", value: result};
1227
1227
  }
1228
1228
  }
1229
+
1230
+ /**
1231
+ * Gets canonical xpath of the passed element, e.g. /HTML[1]/BODY[1]/P[1]
1232
+ */
1233
+ Utils.getXPathOfElement = function(element) {
1234
+ var path = "";
1235
+ for (; element && element.nodeType == 1; element = element.parentNode) {
1236
+ index = Utils.getElementIndexForXPath_(element);
1237
+ path = "/" + element.tagName + "[" + index + "]" + path;
1238
+ }
1239
+ return path;
1240
+ }
1241
+
1242
+ /**
1243
+ * Returns n for the nth child of the parent of that element, of type element.tagName, starting at 1
1244
+ */
1245
+ Utils.getElementIndexForXPath_ = function (element) {
1246
+ var index = 1;
1247
+ for (var sibling = element.previousSibling; sibling ; sibling = sibling.previousSibling) {
1248
+ if (sibling.nodeType == 1 && sibling.tagName == element.tagName) {
1249
+ index++;
1250
+ }
1251
+ }
1252
+ return index;
1253
+ }
@@ -44,7 +44,7 @@ module Selenium
44
44
  # ensure we're ok
45
45
  sleep 0.3
46
46
  if @process.ugly_death?
47
- raise Error::WebDriverError, "Unable to start Firefox cleanly, args: #{args.inspect}, status: #{status.inspect}"
47
+ raise Error::WebDriverError, "unable to start Firefox cleanly, args: #{args.inspect}"
48
48
  end
49
49
  end
50
50
 
@@ -63,16 +63,16 @@ module Selenium
63
63
  private
64
64
 
65
65
  def path
66
- @path ||= case Platform.os
67
- when :macosx
68
- "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
69
- when :windows
70
- windows_path
71
- when :linux, :unix
72
- "/usr/bin/firefox"
73
- else
74
- raise "Unknown platform: #{Platform.os}"
75
- end
66
+ @path ||= case Platform.os
67
+ when :macosx
68
+ "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
69
+ when :windows
70
+ windows_path
71
+ when :linux, :unix
72
+ "/usr/bin/firefox"
73
+ else
74
+ raise "Unknown platform: #{Platform.os}"
75
+ end
76
76
  end
77
77
 
78
78
  def check_binary_exists
@@ -31,7 +31,7 @@ module Selenium
31
31
  def getCurrentUrl
32
32
  create_string do |wrapper|
33
33
  check_error_code Lib.wdGetCurrentUrl(@driver_pointer, wrapper),
34
- "Unable to get current URL"
34
+ "unable to get current URL"
35
35
  end
36
36
  end
37
37
 
@@ -48,20 +48,20 @@ module Selenium
48
48
  def getTitle
49
49
  create_string do |wrapper|
50
50
  check_error_code Lib.wdGetTitle(@driver_pointer, wrapper),
51
- "Unable to get title"
51
+ "unable to get title"
52
52
  end
53
53
  end
54
54
 
55
55
  def getPageSource
56
56
  create_string do |wrapper|
57
57
  check_error_code Lib.wdGetPageSource(@driver_pointer, wrapper),
58
- "Unable to get page source"
58
+ "unable to get page source"
59
59
  end
60
60
  end
61
61
 
62
62
  def getBrowserVisible
63
63
  int_ptr = FFI::MemoryPointer.new :int
64
- check_error_code Lib.wdGetVisible(@driver_pointer, int_ptr), "Unable to determine if browser is visible"
64
+ check_error_code Lib.wdGetVisible(@driver_pointer, int_ptr), "unable to determine if browser is visible"
65
65
 
66
66
  int_ptr.get_int(0) == 1
67
67
  ensure
@@ -70,23 +70,23 @@ module Selenium
70
70
 
71
71
  def setBrowserVisible(bool)
72
72
  check_error_code Lib.wdSetVisible(@driver_pointer, bool ? 1 : 0),
73
- "Unable to change the visibility of the browser"
73
+ "unable to change the visibility of the browser"
74
74
  end
75
75
 
76
76
  def switchToWindow(id)
77
77
  check_error_code Lib.wdSwitchToWindow(@driver_pointer, wstring_ptr(id)),
78
- "Unable to locate window #{id.inspect}"
78
+ "unable to locate window #{id.inspect}"
79
79
  end
80
80
 
81
81
  def switchToFrame(id)
82
82
  check_error_code Lib.wdSwitchToFrame(@driver_pointer, wstring_ptr(id)),
83
- "Unable to locate frame #{id.inspect}"
83
+ "unable to locate frame #{id.inspect}"
84
84
  end
85
85
 
86
86
  def switchToActiveElement
87
87
  create_element do |ptr|
88
88
  check_error_code Lib.wdSwitchToActiveElement(@driver_pointer, ptr),
89
- "Unable to switch to active element"
89
+ "unable to switch to active element"
90
90
  end
91
91
  end
92
92
 
@@ -107,17 +107,17 @@ module Selenium
107
107
  end
108
108
 
109
109
  def close
110
- check_error_code Lib.wdClose(@driver_pointer), "Unable to close driver"
110
+ check_error_code Lib.wdClose(@driver_pointer), "unable to close driver"
111
111
  end
112
112
 
113
113
  def refresh
114
- raise Error::UnsupportedOperationError
114
+ check_error_code Lib.wdRefresh(@driver_pointer), "unable to refresh current page"
115
115
  end
116
116
 
117
117
  def getWindowHandles
118
118
  raw_handles = FFI::MemoryPointer.new :pointer
119
119
  check_error_code Lib.wdGetAllWindowHandles(@driver_pointer, raw_handles),
120
- "Unable to obtain all window handles"
120
+ "unable to obtain all window handles"
121
121
 
122
122
  string_array_from(raw_handles).uniq
123
123
  # TODO: who calls raw_handles.free if exception is raised?
@@ -126,7 +126,7 @@ module Selenium
126
126
  def getCurrentWindowHandle
127
127
  create_string do |string_pointer|
128
128
  check_error_code Lib.wdGetCurrentWindowHandle(@driver_pointer, string_pointer),
129
- "Unable to obtain current window handle"
129
+ "unable to obtain current window handle"
130
130
  end
131
131
  end
132
132
 
@@ -134,7 +134,7 @@ module Selenium
134
134
  script_args_ref = FFI::MemoryPointer.new :pointer
135
135
  result = Lib.wdNewScriptArgs(script_args_ref, args.size)
136
136
 
137
- check_error_code result, "Unable to create new script arguments array"
137
+ check_error_code result, "unable to create new script arguments array"
138
138
 
139
139
  args_pointer = script_args_ref.get_pointer(0)
140
140
  populate_arguments(result, args_pointer, args)
@@ -166,12 +166,12 @@ module Selenium
166
166
  cookie_string << "domain=#{opts[:domain][/^(.+?):/, 1]};" if opts[:domain] && !opts[:domain].empty?
167
167
 
168
168
  check_error_code Lib.wdAddCookie(@driver_pointer, wstring_ptr(cookie_string)),
169
- "Unable to add cookie"
169
+ "unable to add cookie"
170
170
  end
171
171
 
172
172
  def getAllCookies
173
173
  str = create_string do |wrapper|
174
- check_error_code Lib.wdGetCookies(@driver_pointer, wrapper), "Unable to get cookies"
174
+ check_error_code Lib.wdGetCookies(@driver_pointer, wrapper), "unable to get cookies"
175
175
  end
176
176
 
177
177
  str.split("; ").map do |cookie_string|
@@ -214,7 +214,7 @@ module Selenium
214
214
 
215
215
  create_element do |raw_element|
216
216
  check_error_code Lib.wdFindElementByClassName(@driver_pointer, parent, wstring_ptr(class_name), raw_element),
217
- "Unable to find element by class name using #{class_name.inspect}"
217
+ "unable to find element by class name using #{class_name.inspect}"
218
218
  end
219
219
  end
220
220
 
@@ -223,84 +223,84 @@ module Selenium
223
223
 
224
224
  create_element_collection do |raw_elements|
225
225
  check_error_code Lib.wdFindElementsByClassName(@driver_pointer, parent, wstring_ptr(class_name), raw_elements),
226
- "Unable to find elements by class name using #{class_name.inspect}"
226
+ "unable to find elements by class name using #{class_name.inspect}"
227
227
  end
228
228
  end
229
229
 
230
230
  def findElementById(parent, id)
231
231
  create_element do |raw_element|
232
232
  check_error_code Lib.wdFindElementById(@driver_pointer, parent, wstring_ptr(id), raw_element),
233
- "Unable to find element by id using #{id.inspect}"
233
+ "unable to find element by id using #{id.inspect}"
234
234
  end
235
235
  end
236
236
 
237
237
  def findElementsById(parent, id)
238
238
  create_element_collection do |raw_elements|
239
239
  check_error_code Lib.wdFindElementsById(@driver_pointer, parent, wstring_ptr(id), raw_elements),
240
- "Unable to find elements by id using #{id.inspect}"
240
+ "unable to find elements by id using #{id.inspect}"
241
241
  end
242
242
  end
243
243
 
244
244
  def findElementByLinkText(parent, link_text)
245
245
  create_element do |raw_element|
246
246
  check_error_code Lib.wdFindElementByLinkText(@driver_pointer, parent, wstring_ptr(link_text), raw_element),
247
- "Unable to find element by link text using #{link_text.inspect}"
247
+ "unable to find element by link text using #{link_text.inspect}"
248
248
  end
249
249
  end
250
250
 
251
251
  def findElementsByLinkText(parent, link_text)
252
252
  create_element_collection do |raw_elements|
253
253
  check_error_code Lib.wdFindElementsByLinkText(@driver_pointer, parent, wstring_ptr(link_text), raw_elements),
254
- "Unable to find elements by link text using #{link_text.inspect}"
254
+ "unable to find elements by link text using #{link_text.inspect}"
255
255
  end
256
256
  end
257
257
 
258
258
  def findElementByPartialLinkText(parent, link_text)
259
259
  create_element do |raw_element|
260
260
  check_error_code Lib.wdFindElementByPartialLinkText(@driver_pointer, parent, wstring_ptr(link_text), raw_element),
261
- "Unable to find element by partial link text using #{link_text.inspect}"
261
+ "unable to find element by partial link text using #{link_text.inspect}"
262
262
  end
263
263
  end
264
264
 
265
265
  def findElementsByPartialLinkText(parent, link_text)
266
266
  create_element_collection do |raw_elements|
267
267
  check_error_code Lib.wdFindElementsByPartialLinkText(@driver_pointer, parent, wstring_ptr(link_text), raw_elements),
268
- "Unable to find elements by partial link text using #{link_text.inspect}"
268
+ "unable to find elements by partial link text using #{link_text.inspect}"
269
269
  end
270
270
  end
271
271
 
272
272
  def findElementByName(parent, name)
273
273
  create_element do |raw_element|
274
274
  check_error_code Lib.wdFindElementByName(@driver_pointer, parent, wstring_ptr(name), raw_element),
275
- "Unable to find element by name using #{name.inspect}"
275
+ "unable to find element by name using #{name.inspect}"
276
276
  end
277
277
  end
278
278
 
279
279
  def findElementsByName(parent, name)
280
280
  create_element_collection do |raw_elements|
281
281
  check_error_code Lib.wdFindElementsByName(@driver_pointer, parent, wstring_ptr(name), raw_elements),
282
- "Unable to find elements by name using #{name.inspect}"
282
+ "unable to find elements by name using #{name.inspect}"
283
283
  end
284
284
  end
285
285
 
286
286
  def findElementByTagName(parent, tag_name)
287
287
  create_element do |raw_element|
288
288
  check_error_code Lib.wdFindElementByTagName(@driver_pointer, parent, wstring_ptr(tag_name), raw_element),
289
- "Unable to find element by tag name using #{tag_name.inspect}"
289
+ "unable to find element by tag name using #{tag_name.inspect}"
290
290
  end
291
291
  end
292
292
 
293
293
  def findElementsByTagName(parent, tag_name)
294
294
  create_element_collection do |raw_elements|
295
295
  check_error_code Lib.wdFindElementsByTagName(@driver_pointer, parent, wstring_ptr(tag_name), raw_elements),
296
- "Unable to find elements by tag name using #{tag_name.inspect}"
296
+ "unable to find elements by tag name using #{tag_name.inspect}"
297
297
  end
298
298
  end
299
299
 
300
300
  def findElementByXpath(parent, xpath)
301
301
  create_element do |raw_element|
302
302
  check_error_code Lib.wdFindElementByXPath(@driver_pointer, parent, wstring_ptr(xpath), raw_element),
303
- "Unable to find element by xpath using #{xpath.inspect}"
303
+ "unable to find element by xpath using #{xpath.inspect}"
304
304
  # TODO: Additional error handling
305
305
  end
306
306
  end
@@ -308,7 +308,7 @@ module Selenium
308
308
  def findElementsByXpath(parent, xpath)
309
309
  create_element_collection do |raw_elements|
310
310
  check_error_code Lib.wdFindElementsByXPath(@driver_pointer, parent, wstring_ptr(xpath), raw_elements),
311
- "Unable to find elements by xpath using #{xpath.inspect}"
311
+ "unable to find elements by xpath using #{xpath.inspect}"
312
312
  # TODO: Additional error handling
313
313
  end
314
314
  end
@@ -319,20 +319,20 @@ module Selenium
319
319
  #
320
320
 
321
321
  def clickElement(element_pointer)
322
- check_error_code Lib.wdeClick(element_pointer), "Unable to click element"
322
+ check_error_code Lib.wdeClick(element_pointer), "unable to click element"
323
323
  end
324
324
 
325
325
  def getElementTagName(element_pointer)
326
326
  create_string do |string_pointer|
327
327
  check_error_code Lib.wdeGetTagName(element_pointer, string_pointer),
328
- "Unable to get tag name"
328
+ "unable to get tag name"
329
329
  end
330
330
  end
331
331
 
332
332
  def getElementAttribute(element_pointer, name)
333
333
  create_string do |string_pointer|
334
334
  check_error_code Lib.wdeGetAttribute(element_pointer, wstring_ptr(name), string_pointer),
335
- "Unable to get attribute #{name.inspect}"
335
+ "unable to get attribute #{name.inspect}"
336
336
  end
337
337
  end
338
338
 
@@ -343,24 +343,24 @@ module Selenium
343
343
  def getElementText(element_pointer)
344
344
  create_string do |string_pointer|
345
345
  check_error_code Lib.wdeGetText(element_pointer, string_pointer),
346
- "Unable to get text"
346
+ "unable to get text"
347
347
  end.gsub("\r\n", "\n")
348
348
  end
349
349
 
350
350
  def sendKeysToElement(element_pointer, string)
351
351
  check_error_code Lib.wdeSendKeys(element_pointer, wstring_ptr(string)),
352
- "Unable to send keys to #{self}"
352
+ "unable to send keys to #{self}"
353
353
  waitForLoadToComplete
354
354
  end
355
355
 
356
356
  def clearElement(element_pointer)
357
- check_error_code Lib.wdeClear(element_pointer), "Unable to clear element"
357
+ check_error_code Lib.wdeClear(element_pointer), "unable to clear element"
358
358
  end
359
359
 
360
360
  def isElementEnabled(element_pointer)
361
361
  int_ptr = FFI::MemoryPointer.new(:int)
362
362
  check_error_code Lib.wdeIsEnabled(element_pointer, int_ptr),
363
- "Unable to get enabled state"
363
+ "unable to get enabled state"
364
364
 
365
365
  int_ptr.get_int(0) == 1
366
366
  ensure
@@ -370,7 +370,7 @@ module Selenium
370
370
  def isElementSelected(element_pointer)
371
371
  int_ptr = FFI::MemoryPointer.new(:int)
372
372
  check_error_code Lib.wdeIsSelected(element_pointer, int_ptr),
373
- "Unable to get selected state"
373
+ "unable to get selected state"
374
374
 
375
375
  int_ptr.get_int(0) == 1
376
376
  ensure
@@ -379,7 +379,7 @@ module Selenium
379
379
 
380
380
  def isElementDisplayed(element_pointer)
381
381
  int_ptr = FFI::MemoryPointer.new :int
382
- check_error_code Lib.wdeIsDisplayed(element_pointer, int_ptr), "Unable to check visibilty"
382
+ check_error_code Lib.wdeIsDisplayed(element_pointer, int_ptr), "unable to check visibilty"
383
383
 
384
384
  int_ptr.get_int(0) == 1;
385
385
  ensure
@@ -387,7 +387,7 @@ module Selenium
387
387
  end
388
388
 
389
389
  def submitElement(element_pointer)
390
- check_error_code Lib.wdeSubmit(element_pointer), "Unable to submit element"
390
+ check_error_code Lib.wdeSubmit(element_pointer), "unable to submit element"
391
391
  end
392
392
 
393
393
  def toggleElement(element_pointer)
@@ -399,7 +399,7 @@ module Selenium
399
399
  "You may not toggle this element: #{get_element_tag_name(element_pointer)}"
400
400
  end
401
401
 
402
- check_error_code result, "Unable to toggle element"
402
+ check_error_code result, "unable to toggle element"
403
403
 
404
404
  int_ptr.get_int(0) == 1
405
405
  ensure
@@ -407,13 +407,13 @@ module Selenium
407
407
  end
408
408
 
409
409
  def setElementSelected(element_pointer)
410
- check_error_code Lib.wdeSetSelected(element_pointer), "Unable to select element"
410
+ check_error_code Lib.wdeSetSelected(element_pointer), "unable to select element"
411
411
  end
412
412
 
413
413
  def getElementValueOfCssProperty(element_pointer, prop)
414
414
  create_string do |string_pointer|
415
415
  check_error_code Lib.wdeGetValueOfCssProperty(element_pointer, wstring_ptr(prop), string_pointer),
416
- "Unable to get value of css property: #{prop.inspect}"
416
+ "unable to get value of css property: #{prop.inspect}"
417
417
  end
418
418
  end
419
419
 
@@ -427,7 +427,7 @@ module Selenium
427
427
  x, y, width, height = Array.new(4) { FFI::MemoryPointer.new :long }
428
428
 
429
429
  check_error_code Lib.wdeGetDetailsOnceScrolledOnToScreen(element_pointer, hwnd, x, y, width, height),
430
- "Unable to determine location once scrolled on to screen"
430
+ "unable to determine location once scrolled on to screen"
431
431
 
432
432
  Lib.wdeMouseDownAt(hwnd.get_pointer(0), x.get_long(0), y.get_long(0))
433
433
 
@@ -445,7 +445,7 @@ module Selenium
445
445
  x = FFI::MemoryPointer.new :long
446
446
  y = FFI::MemoryPointer.new :long
447
447
 
448
- check_error_code Lib.wdeGetLocation(element_pointer, x, y), "Unable to get location of element"
448
+ check_error_code Lib.wdeGetLocation(element_pointer, x, y), "unable to get location of element"
449
449
 
450
450
  Point.new x.get_int(0), y.get_int(0)
451
451
  ensure
@@ -457,7 +457,7 @@ module Selenium
457
457
  width = FFI::MemoryPointer.new :long
458
458
  height = FFI::MemoryPointer.new :long
459
459
 
460
- check_error_code Lib.wdeGetSize(element_pointer, width, height), "Unable to get size of element"
460
+ check_error_code Lib.wdeGetSize(element_pointer, width, height), "unable to get size of element"
461
461
 
462
462
  Dimension.new width.get_int(0), height.get_int(0)
463
463
  ensure
@@ -467,7 +467,7 @@ module Selenium
467
467
 
468
468
  def finalize(element_pointer)
469
469
  check_error_code Lib.wdeFreeElement(element_pointer),
470
- "Unable to finalize #{element_pointer} for #{self}"
470
+ "unable to finalize #{element_pointer} for #{self}"
471
471
  end
472
472
 
473
473
  private
@@ -489,7 +489,7 @@ module Selenium
489
489
  raise TypeError, "Parameter is not of recognized type: #{arg.inspect}:#{arg.class}"
490
490
  end
491
491
 
492
- check_error_code result, "Unable to add argument: #{arg.inspect}"
492
+ check_error_code result, "unable to add argument: #{arg.inspect}"
493
493
  end
494
494
 
495
495
 
@@ -77,6 +77,7 @@ module Selenium
77
77
  attach_function :wdGoForward, [:pointer ], :int
78
78
  attach_function :wdNewDriverInstance, [:pointer ], :int
79
79
  attach_function :wdNewScriptArgs, [:pointer, :int ], :int
80
+ attach_function :wdRefresh, [:pointer, ], :int
80
81
  attach_function :wdSetVisible, [:pointer, :int ], :int
81
82
  attach_function :wdStringLength, [:pointer, :pointer ], :int
82
83
  attach_function :wdSwitchToActiveElement, [:pointer, :pointer ], :int
@@ -97,7 +97,7 @@ module Selenium
97
97
 
98
98
  if e = WebDriver::Error.for_code(result)
99
99
  Lib.wdFreeElementCollection(elements_ptr, 1)
100
- raise e, "Unable to create element from collection at index #{idx} (#{result})"
100
+ raise e, "unable to create element from collection at index #{idx} (#{result})"
101
101
  end
102
102
  end
103
103
  end
@@ -116,7 +116,7 @@ module Selenium
116
116
  size = Kernel32.MultiByteToWideChar(CP_UTF8, 0, str, -1, nil, 0)
117
117
 
118
118
  unless size > 0
119
- raise Error::WebDriverError, "could not convert #{str.inspect} to wchar ptr"
119
+ raise Error::WebDriverError, "unable to convert #{str.inspect} to wchar ptr"
120
120
  end
121
121
 
122
122
  buf = FFI::MemoryPointer.new :pointer, size
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-webdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-14 00:00:00 +01:00
12
+ date: 2009-12-15 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency