browserstack-webdriver 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +791 -0
  3. data/README.md +31 -0
  4. data/build.desc +334 -0
  5. data/lib/selenium-client.rb +2 -0
  6. data/lib/selenium-webdriver.rb +1 -0
  7. data/lib/selenium/client.rb +37 -0
  8. data/lib/selenium/client/base.rb +132 -0
  9. data/lib/selenium/client/driver.rb +10 -0
  10. data/lib/selenium/client/errors.rb +9 -0
  11. data/lib/selenium/client/extensions.rb +118 -0
  12. data/lib/selenium/client/idiomatic.rb +488 -0
  13. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  14. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  15. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  16. data/lib/selenium/client/legacy_driver.rb +1720 -0
  17. data/lib/selenium/client/protocol.rb +104 -0
  18. data/lib/selenium/client/selenium_helper.rb +34 -0
  19. data/lib/selenium/rake/server_task.rb +157 -0
  20. data/lib/selenium/server.rb +248 -0
  21. data/lib/selenium/webdriver.rb +71 -0
  22. data/lib/selenium/webdriver/android.rb +9 -0
  23. data/lib/selenium/webdriver/android/bridge.rb +47 -0
  24. data/lib/selenium/webdriver/chrome.rb +26 -0
  25. data/lib/selenium/webdriver/chrome/bridge.rb +120 -0
  26. data/lib/selenium/webdriver/chrome/profile.rb +90 -0
  27. data/lib/selenium/webdriver/chrome/service.rb +75 -0
  28. data/lib/selenium/webdriver/common.rb +44 -0
  29. data/lib/selenium/webdriver/common/action_builder.rb +352 -0
  30. data/lib/selenium/webdriver/common/alert.rb +30 -0
  31. data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
  32. data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
  33. data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
  34. data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
  35. data/lib/selenium/webdriver/common/driver.rb +301 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/has_browser_connection.rb +17 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
  38. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +25 -0
  39. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +13 -0
  40. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +22 -0
  41. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +19 -0
  42. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +22 -0
  43. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +45 -0
  44. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
  45. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
  46. data/lib/selenium/webdriver/common/element.rb +293 -0
  47. data/lib/selenium/webdriver/common/error.rb +207 -0
  48. data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
  49. data/lib/selenium/webdriver/common/html5/local_storage.rb +42 -0
  50. data/lib/selenium/webdriver/common/html5/location.rb +0 -0
  51. data/lib/selenium/webdriver/common/html5/session_storage.rb +44 -0
  52. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +42 -0
  53. data/lib/selenium/webdriver/common/json_helper.rb +34 -0
  54. data/lib/selenium/webdriver/common/keyboard.rb +55 -0
  55. data/lib/selenium/webdriver/common/keys.rb +109 -0
  56. data/lib/selenium/webdriver/common/log_entry.rb +29 -0
  57. data/lib/selenium/webdriver/common/logs.rb +23 -0
  58. data/lib/selenium/webdriver/common/mouse.rb +72 -0
  59. data/lib/selenium/webdriver/common/navigation.rb +43 -0
  60. data/lib/selenium/webdriver/common/options.rb +136 -0
  61. data/lib/selenium/webdriver/common/platform.rb +218 -0
  62. data/lib/selenium/webdriver/common/port_prober.rb +42 -0
  63. data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
  64. data/lib/selenium/webdriver/common/proxy.rb +149 -0
  65. data/lib/selenium/webdriver/common/search_context.rb +92 -0
  66. data/lib/selenium/webdriver/common/socket_poller.rb +105 -0
  67. data/lib/selenium/webdriver/common/target_locator.rb +81 -0
  68. data/lib/selenium/webdriver/common/timeouts.rb +38 -0
  69. data/lib/selenium/webdriver/common/touch_action_builder.rb +64 -0
  70. data/lib/selenium/webdriver/common/touch_screen.rb +105 -0
  71. data/lib/selenium/webdriver/common/wait.rb +63 -0
  72. data/lib/selenium/webdriver/common/window.rb +104 -0
  73. data/lib/selenium/webdriver/common/zipper.rb +82 -0
  74. data/lib/selenium/webdriver/firefox.rb +37 -0
  75. data/lib/selenium/webdriver/firefox/binary.rb +158 -0
  76. data/lib/selenium/webdriver/firefox/bridge.rb +70 -0
  77. data/lib/selenium/webdriver/firefox/extension.rb +52 -0
  78. data/lib/selenium/webdriver/firefox/launcher.rb +106 -0
  79. data/lib/selenium/webdriver/firefox/profile.rb +263 -0
  80. data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
  81. data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
  82. data/lib/selenium/webdriver/firefox/util.rb +29 -0
  83. data/lib/selenium/webdriver/ie.rb +19 -0
  84. data/lib/selenium/webdriver/ie/bridge.rb +68 -0
  85. data/lib/selenium/webdriver/ie/server.rb +86 -0
  86. data/lib/selenium/webdriver/iphone.rb +9 -0
  87. data/lib/selenium/webdriver/iphone/bridge.rb +45 -0
  88. data/lib/selenium/webdriver/opera.rb +24 -0
  89. data/lib/selenium/webdriver/opera/bridge.rb +112 -0
  90. data/lib/selenium/webdriver/opera/service.rb +49 -0
  91. data/lib/selenium/webdriver/phantomjs.rb +22 -0
  92. data/lib/selenium/webdriver/phantomjs/bridge.rb +59 -0
  93. data/lib/selenium/webdriver/phantomjs/service.rb +90 -0
  94. data/lib/selenium/webdriver/remote.rb +22 -0
  95. data/lib/selenium/webdriver/remote/bridge.rb +644 -0
  96. data/lib/selenium/webdriver/remote/capabilities.rb +267 -0
  97. data/lib/selenium/webdriver/remote/commands.rb +193 -0
  98. data/lib/selenium/webdriver/remote/http/common.rb +74 -0
  99. data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
  100. data/lib/selenium/webdriver/remote/http/default.rb +139 -0
  101. data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
  102. data/lib/selenium/webdriver/remote/response.rb +97 -0
  103. data/lib/selenium/webdriver/remote/server_error.rb +17 -0
  104. data/lib/selenium/webdriver/safari.rb +46 -0
  105. data/lib/selenium/webdriver/safari/bridge.rb +110 -0
  106. data/lib/selenium/webdriver/safari/browser.rb +20 -0
  107. data/lib/selenium/webdriver/safari/extension.rb +120 -0
  108. data/lib/selenium/webdriver/safari/server.rb +145 -0
  109. data/lib/selenium/webdriver/support.rb +5 -0
  110. data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
  111. data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
  112. data/lib/selenium/webdriver/support/color.rb +110 -0
  113. data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
  114. data/lib/selenium/webdriver/support/select.rb +293 -0
  115. data/ruby.iml +13 -0
  116. data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
  117. data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
  118. data/spec/integration/selenium/client/api/click_spec.rb +39 -0
  119. data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
  120. data/spec/integration/selenium/client/api/element_spec.rb +14 -0
  121. data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
  122. data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
  123. data/spec/integration/selenium/client/api/screenshot_spec.rb +31 -0
  124. data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
  125. data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
  126. data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
  127. data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
  128. data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
  129. data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
  130. data/spec/integration/selenium/client/api/webdriver_backed_spec.rb +21 -0
  131. data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
  132. data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
  133. data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
  134. data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
  135. data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
  136. data/spec/integration/selenium/client/spec_helper.rb +139 -0
  137. data/spec/integration/selenium/webdriver/app_cache_spec.rb +47 -0
  138. data/spec/integration/selenium/webdriver/browser_connection_spec.rb +20 -0
  139. data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
  140. data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +63 -0
  141. data/spec/integration/selenium/webdriver/driver_spec.rb +266 -0
  142. data/spec/integration/selenium/webdriver/element_spec.rb +191 -0
  143. data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
  144. data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
  145. data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
  146. data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
  147. data/spec/integration/selenium/webdriver/location_spec.rb +29 -0
  148. data/spec/integration/selenium/webdriver/mouse_spec.rb +57 -0
  149. data/spec/integration/selenium/webdriver/navigation_spec.rb +46 -0
  150. data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
  151. data/spec/integration/selenium/webdriver/options_spec.rb +77 -0
  152. data/spec/integration/selenium/webdriver/remote/driver_spec.rb +19 -0
  153. data/spec/integration/selenium/webdriver/remote/element_spec.rb +26 -0
  154. data/spec/integration/selenium/webdriver/spec_helper.rb +36 -0
  155. data/spec/integration/selenium/webdriver/spec_support.rb +12 -0
  156. data/spec/integration/selenium/webdriver/spec_support/guards.rb +110 -0
  157. data/spec/integration/selenium/webdriver/spec_support/helpers.rb +51 -0
  158. data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
  159. data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +239 -0
  160. data/spec/integration/selenium/webdriver/sql_database_spec.rb +59 -0
  161. data/spec/integration/selenium/webdriver/storage_spec.rb +96 -0
  162. data/spec/integration/selenium/webdriver/target_locator_spec.rb +186 -0
  163. data/spec/integration/selenium/webdriver/timeout_spec.rb +69 -0
  164. data/spec/integration/selenium/webdriver/touch_spec.rb +176 -0
  165. data/spec/integration/selenium/webdriver/window_spec.rb +70 -0
  166. data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
  167. data/spec/unit/selenium/client/base_spec.rb +239 -0
  168. data/spec/unit/selenium/client/extensions_spec.rb +174 -0
  169. data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
  170. data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
  171. data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
  172. data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
  173. data/spec/unit/selenium/client/protocol_spec.rb +124 -0
  174. data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
  175. data/spec/unit/selenium/client/spec_helper.rb +24 -0
  176. data/spec/unit/selenium/rake/task_spec.rb +79 -0
  177. data/spec/unit/selenium/server_spec.rb +150 -0
  178. data/spec/unit/selenium/webdriver/action_builder_spec.rb +97 -0
  179. data/spec/unit/selenium/webdriver/android/bridge_spec.rb +43 -0
  180. data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +137 -0
  181. data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
  182. data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
  183. data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
  184. data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +47 -0
  185. data/spec/unit/selenium/webdriver/ie/bridge_spec.rb +91 -0
  186. data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +42 -0
  187. data/spec/unit/selenium/webdriver/log_entry_spec.rb +11 -0
  188. data/spec/unit/selenium/webdriver/opera/bridge_spec.rb +44 -0
  189. data/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb +55 -0
  190. data/spec/unit/selenium/webdriver/proxy_spec.rb +106 -0
  191. data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
  192. data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +115 -0
  193. data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
  194. data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +124 -0
  195. data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
  196. data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
  197. data/spec/unit/selenium/webdriver/spec_helper.rb +27 -0
  198. data/spec/unit/selenium/webdriver/support/color_spec.rb +119 -0
  199. data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
  200. data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
  201. data/spec/unit/selenium/webdriver/wait_spec.rb +49 -0
  202. metadata +370 -0
@@ -0,0 +1,13 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module DriverExtensions
4
+ module HasRemoteStatus
5
+
6
+ def remote_status
7
+ @bridge.status
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # @api private
6
+ #
7
+
8
+ module DriverExtensions
9
+ module HasSessionId
10
+
11
+ #
12
+ # @return [String] the session id
13
+ # @api public
14
+ #
15
+
16
+ def session_id
17
+ @bridge.session_id
18
+ end
19
+ end # HasSessionId
20
+ end # DriverExtensions
21
+ end # WebDriver
22
+ end # Selenium
@@ -0,0 +1,19 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module DriverExtensions
4
+
5
+ module HasTouchScreen
6
+ def touch
7
+ TouchActionBuilder.new mouse, keyboard, touch_screen
8
+ end
9
+
10
+ private
11
+
12
+ def touch_screen
13
+ TouchScreen.new @bridge
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # @api private
6
+ #
7
+
8
+ module DriverExtensions
9
+ module HasWebStorage
10
+
11
+ def local_storage
12
+ HTML5::LocalStorage.new @bridge
13
+ end
14
+
15
+ def session_storage
16
+ HTML5::SessionStorage.new @bridge
17
+ end
18
+
19
+ end # HasWebStorage
20
+ end # DriverExtensions
21
+ end # WebDriver
22
+ end # Selenium
@@ -0,0 +1,45 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # @api private
6
+ #
7
+
8
+ module DriverExtensions
9
+ module Rotatable
10
+
11
+ ORIENTATIONS = [:landscape, :portrait]
12
+
13
+ #
14
+ # Change the screen orientation
15
+ #
16
+ # @param [:landscape, :portrait] Orientation
17
+ #
18
+ # @api public
19
+ #
20
+
21
+ def rotation=(orientation)
22
+ unless ORIENTATIONS.include?(orientation)
23
+ raise ArgumentError, "expected #{ORIENTATIONS.inspect}, got #{orientation.inspect}"
24
+ end
25
+
26
+ bridge.setScreenOrientation(orientation.to_s.upcase)
27
+ end
28
+ alias_method :rotate, :rotation=
29
+
30
+ #
31
+ # Get the current screen orientation
32
+ #
33
+ # @return [:landscape, :portrait] orientation
34
+ #
35
+ # @api public
36
+ #
37
+
38
+ def orientation
39
+ bridge.getScreenOrientation.to_sym.downcase
40
+ end
41
+
42
+ end # Rotatable
43
+ end # DriverExtensions
44
+ end # WebDriver
45
+ end # Selenium
@@ -0,0 +1,43 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # @api private
6
+ #
7
+
8
+ module DriverExtensions
9
+ module TakesScreenshot
10
+
11
+ #
12
+ # Save a PNG screenshot to the given path
13
+ #
14
+ # @api public
15
+ #
16
+
17
+ def save_screenshot(png_path)
18
+ File.open(png_path, 'wb') { |f| f << screenshot_as(:png) }
19
+ end
20
+
21
+ #
22
+ # Return a PNG screenshot in the given format as a string
23
+ #
24
+ # @param [:base64, :png] format
25
+ # @return String screenshot
26
+ #
27
+ # @api public
28
+
29
+ def screenshot_as(format)
30
+ case format
31
+ when :base64
32
+ bridge.getScreenshot
33
+ when :png
34
+ bridge.getScreenshot.unpack("m")[0]
35
+ else
36
+ raise Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
37
+ end
38
+ end
39
+
40
+ end # TakesScreenshot
41
+ end # DriverExtensions
42
+ end # WebDriver
43
+ end # Selenium
@@ -0,0 +1,46 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # @api private
6
+ #
7
+
8
+ module DriverExtensions
9
+ module UploadsFiles
10
+
11
+ #
12
+ # Set the file detector to pass local files to a remote WebDriver.
13
+ #
14
+ # The detector is an object that responds to #call, and when called
15
+ # will determine if the given string represents a file. If it does,
16
+ # the path to the file on the local file system should be returned,
17
+ # otherwise nil or false.
18
+ #
19
+ # Example:
20
+ #
21
+ # driver = Selenium::WebDriver.for :remote
22
+ # driver.file_detector = lambda do |args|
23
+ # # args => ["/path/to/file"]
24
+ # str = args.first.to_s
25
+ # str if File.exist?(str)
26
+ # end
27
+ #
28
+ # driver.find_element(:id => "upload").send_keys "/path/to/file"
29
+ #
30
+ # By default, no file detection is performed.
31
+ #
32
+ # @api public
33
+ #
34
+
35
+ def file_detector=(detector)
36
+ unless detector.nil? or detector.respond_to? :call
37
+ raise ArgumentError, "detector must respond to #call"
38
+ end
39
+
40
+ bridge.file_detector = detector
41
+ end
42
+
43
+ end # UploadsFiles
44
+ end # DriverExtensions
45
+ end # WebDriver
46
+ end # Selenium
@@ -0,0 +1,293 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class Element
4
+ include SearchContext
5
+
6
+ #
7
+ # Creates a new Element
8
+ #
9
+ # @api private
10
+ #
11
+
12
+ def initialize(bridge, id)
13
+ @bridge, @id = bridge, id
14
+ end
15
+
16
+ def inspect
17
+ '#<%s:0x%x id=%s>' % [self.class, hash*2, @id.inspect]
18
+ end
19
+
20
+ def ==(other)
21
+ other.kind_of?(self.class) && bridge.elementEquals(self, other)
22
+ end
23
+ alias_method :eql?, :==
24
+
25
+ def hash
26
+ @id.hash ^ @bridge.hash
27
+ end
28
+
29
+ #
30
+ # Click this element. If this causes a new page to load, this method will
31
+ # attempt to block until the page has loaded. At this point, you should
32
+ # discard all references to this element and any further operations
33
+ # performed on this element will raise a StaleElementReferenceError
34
+ # unless you know that the element and the page will still be present. If
35
+ # click() causes a new page to be loaded via an event or is done by
36
+ # sending a native event then the method will *not* wait for it to be
37
+ # loaded and the caller should verify that a new page has been loaded.
38
+ #
39
+ # There are some preconditions for an element to be clicked. The element
40
+ # must be visible and it must have a height and width greater then 0.
41
+ #
42
+ # Equivalent to:
43
+ # driver.action.click(element)
44
+ #
45
+ # @example Click on a button
46
+ #
47
+ # driver.find_element(:tag_name, "button").click
48
+ #
49
+ # @raise [StaleElementReferenceError] if the element no longer exists as
50
+ # defined
51
+ #
52
+
53
+ def click
54
+ bridge.clickElement @id
55
+ end
56
+
57
+ #
58
+ # Get the tag name of the element.
59
+ #
60
+ # @example Get the tagname of an INPUT element(returns "input")
61
+ #
62
+ # driver.find_element(:xpath, "//input").tag_name
63
+ #
64
+ # @return [String] The tag name of this element.
65
+ #
66
+
67
+ def tag_name
68
+ bridge.getElementTagName @id
69
+ end
70
+
71
+ #
72
+ # Get the value of a the given attribute of the element. Will return the current value, even if
73
+ # this has been modified after the page has been loaded. More exactly, this method will return
74
+ # the value of the given attribute, unless that attribute is not present, in which case the
75
+ # value of the property with the same name is returned. If neither value is set, nil is
76
+ # returned. The "style" attribute is converted as best can be to a text representation with a
77
+ # trailing semi-colon. The following are deemed to be "boolean" attributes, and will
78
+ # return either "true" or "false":
79
+ #
80
+ # async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
81
+ # defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,
82
+ # iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate,
83
+ # nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
84
+ # selected, spellcheck, truespeed, willvalidate
85
+ #
86
+ # Finally, the following commonly mis-capitalized attribute/property names are evaluated as
87
+ # expected:
88
+ #
89
+ # class, readonly
90
+ #
91
+ # @param [String]
92
+ # attribute name
93
+ # @return [String,nil]
94
+ # attribute value
95
+ #
96
+
97
+ def attribute(name)
98
+ bridge.getElementAttribute @id, name
99
+ end
100
+
101
+ #
102
+ # Get the text content of this element
103
+ #
104
+ # @return [String]
105
+ #
106
+
107
+ def text
108
+ bridge.getElementText @id
109
+ end
110
+
111
+ #
112
+ # Send keystrokes to this element
113
+ #
114
+ # @param [String, Symbol, Array]
115
+ #
116
+ # Examples:
117
+ #
118
+ # element.send_keys "foo" #=> value: 'foo'
119
+ # element.send_keys "tet", :arrow_left, "s" #=> value: 'test'
120
+ # element.send_keys [:control, 'a'], :space #=> value: ' '
121
+ #
122
+ # @see Keys::KEYS
123
+ #
124
+
125
+ def send_keys(*args)
126
+ bridge.sendKeysToElement @id, Keys.encode(args)
127
+ end
128
+ alias_method :send_key, :send_keys
129
+
130
+ #
131
+ # If this element is a text entry element, this will clear the value. Has no effect on other
132
+ # elements. Text entry elements are INPUT and TEXTAREA elements.
133
+ #
134
+ # Note that the events fired by this event may not be as you'd expect. In particular, we don't
135
+ # fire any keyboard or mouse events. If you want to ensure keyboard events are
136
+ # fired, consider using #send_keys with the backspace key. To ensure you get a change event,
137
+ # consider following with a call to #send_keys with the tab key.
138
+ #
139
+
140
+ def clear
141
+ bridge.clearElement @id
142
+ end
143
+
144
+ #
145
+ # Is the element enabled?
146
+ #
147
+ # @return [Boolean]
148
+ #
149
+
150
+ def enabled?
151
+ bridge.isElementEnabled @id
152
+ end
153
+
154
+ #
155
+ # Is the element selected?
156
+ #
157
+ # @return [Boolean]
158
+ #
159
+
160
+ def selected?
161
+ bridge.isElementSelected @id
162
+ end
163
+
164
+ #
165
+ # Is the element displayed?
166
+ #
167
+ # @return [Boolean]
168
+ #
169
+
170
+ def displayed?
171
+ bridge.isElementDisplayed @id
172
+ end
173
+
174
+ #
175
+ # Submit this element
176
+ #
177
+
178
+ def submit
179
+ bridge.submitElement @id
180
+ end
181
+
182
+ #
183
+ # Get the value of the given CSS property
184
+ #
185
+ # Note that shorthand CSS properties (e.g. background, font, border, border-top, margin,
186
+ # margin-top, padding, padding-top, list-style, outline, pause, cue) are not returned,
187
+ # in accordance with the DOM CSS2 specification - you should directly access the longhand
188
+ # properties (e.g. background-color) to access the desired values.
189
+ #
190
+ # @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration
191
+ #
192
+
193
+ def css_value(prop)
194
+ bridge.getElementValueOfCssProperty @id, prop
195
+ end
196
+ alias_method :style, :css_value
197
+
198
+ #
199
+ # Get the location of this element.
200
+ #
201
+ # @return [WebDriver::Point]
202
+ #
203
+
204
+ def location
205
+ bridge.getElementLocation @id
206
+ end
207
+
208
+ #
209
+ # Determine an element's location on the screen once it has been scrolled into view.
210
+ #
211
+ # @return [WebDriver::Point]
212
+ #
213
+
214
+ def location_once_scrolled_into_view
215
+ bridge.getElementLocationOnceScrolledIntoView @id
216
+ end
217
+
218
+ #
219
+ # Get the size of this element
220
+ #
221
+ # @return [WebDriver::Dimension]
222
+ #
223
+
224
+ def size
225
+ bridge.getElementSize @id
226
+ end
227
+
228
+ #-------------------------------- sugar --------------------------------
229
+
230
+ #
231
+ # element.first(:id, 'foo')
232
+ #
233
+
234
+ alias_method :first, :find_element
235
+
236
+ #
237
+ # element.all(:class, 'bar')
238
+ #
239
+
240
+ alias_method :all, :find_elements
241
+
242
+ #
243
+ # element['class'] or element[:class] #=> "someclass"
244
+ #
245
+ alias_method :[], :attribute
246
+
247
+ #
248
+ # for SearchContext and execute_script
249
+ #
250
+ # @api private
251
+ #
252
+
253
+ def ref
254
+ @id
255
+ end
256
+
257
+ #
258
+ # Convert to a WebElement JSON Object for transmission over the wire.
259
+ # @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#Basic_Concepts_And_Terms
260
+ #
261
+ # @api private
262
+ #
263
+
264
+ def to_json(*args)
265
+ WebDriver.json_dump as_json
266
+ end
267
+
268
+ #
269
+ # For Rails 3 - http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/
270
+ #
271
+ # @api private
272
+ #
273
+
274
+ def as_json(opts = nil)
275
+ { :ELEMENT => @id }
276
+ end
277
+
278
+ private
279
+
280
+ def bridge
281
+ @bridge
282
+ end
283
+
284
+ def selectable?
285
+ tn = tag_name.downcase
286
+ type = attribute(:type).to_s.downcase
287
+
288
+ tn == "option" || (tn == "input" && %w[radio checkbox].include?(type))
289
+ end
290
+
291
+ end # Element
292
+ end # WebDriver
293
+ end # Selenium