Class: Appium::Core::Element
- Inherits:
-
Selenium::WebDriver::Element
- Object
- Selenium::WebDriver::Element
- Appium::Core::Element
- Includes:
- Base::SearchContext, Base::TakesScreenshot
- Defined in:
- lib/appium_lib_core/element.rb
Overview
Implement useful features for element. Patch for Selenium Webdriver.
Constant Summary
Constants included from Base::SearchContext
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
Retuns the element id.
Instance Method Summary collapse
-
#immediate_value(*value) ⇒ Object
deprecated
Deprecated.
Use element send_keys instead.
-
#location_rel(driver) ⇒ ::Selenium::WebDriver::Point
For use with location_rel.
-
#method_missing(method_name, *args, &block) ⇒ String
Returns the value of attributes like below.
-
#replace_value(*value) ⇒ Object
deprecated
Deprecated.
Use element send_keys or ‘mobile: replaceElementValue’ for UIAutomator2 instead.
- #respond_to_missing? ⇒ Boolean
-
#save_screenshot(png_path) ⇒ File
Save an element screenshot to the given path.
-
#screenshot ⇒ Object
Return an element screenshot as base64.
-
#screenshot_as(format) ⇒ Object
Return an element screenshot in the given format.
Methods included from Base::TakesScreenshot
#element_screenshot_as, #save_element_screenshot, #save_viewport_screenshot
Methods included from Base::SearchContext
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ String
Returns the value of attributes like below. Read each platform to know more details.
checkable, checked, class, clickable, content-desc, enabled, focusable, focused
long-clickable, package, password, resource-id, scrollable, selection-start, selection-end
selected, text, bounds, index
XCUITest automation name supports below attributes.
UID, accessibilityContainer, accessible, enabled, frame,
label, name, rect, type, value, visible, wdAccessibilityContainer,
wdAccessible, wdEnabled, wdFrame, wdLabel, wdName, wdRect, wdType,
wdUID, wdValue, wdVisible
53 54 55 56 57 58 |
# File 'lib/appium_lib_core/element.rb', line 53 def method_missing(method_name, *args, &block) ignore_list = [:to_hash] return if ignore_list.include? method_name respond_to?(method_name) ? attribute(method_name.to_s.tr('_', '-')) : super end |
Instance Attribute Details
#id ⇒ String (readonly)
Retuns the element id.
30 31 32 |
# File 'lib/appium_lib_core/element.rb', line 30 def id @id end |
Instance Method Details
#immediate_value(*value) ⇒ Object
Use element send_keys instead.
Set the value to element directly
74 75 76 77 78 79 |
# File 'lib/appium_lib_core/element.rb', line 74 def immediate_value(*value) ::Appium::Logger.warn( '[DEPRECATION] element.immediate_value is deprecated. Please use element.send_keys instead.' ) @bridge.set_immediate_value @id, *value end |
#location_rel(driver) ⇒ ::Selenium::WebDriver::Point
For use with location_rel.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/appium_lib_core/element.rb', line 105 def location_rel(driver) rect = self.rect location_x = rect.x.to_f location_y = rect.y.to_f size_width = rect.width.to_f size_height = rect.height.to_f center_x = location_x + (size_width / 2.0) center_y = location_y + (size_height / 2.0) w = driver.window_size ::Selenium::WebDriver::Point.new "#{center_x} / #{w.width.to_f}", "#{center_y} / #{w.height.to_f}" end |
#replace_value(*value) ⇒ Object
Use element send_keys or ‘mobile: replaceElementValue’ for UIAutomator2 instead.
Replace the value to element directly
88 89 90 91 92 93 94 |
# File 'lib/appium_lib_core/element.rb', line 88 def replace_value(*value) ::Appium::Logger.warn( '[DEPRECATION] element.replace_value is deprecated. Please use element.send_keys instead, ' \ 'or "mobile: replaceElementValue" for UIAutomator2.' ) @bridge.replace_value @id, *value end |
#respond_to_missing? ⇒ Boolean
60 61 62 |
# File 'lib/appium_lib_core/element.rb', line 60 def respond_to_missing?(*) true end |
#save_screenshot(png_path) ⇒ File
Save an element screenshot to the given path
161 162 163 164 165 166 167 168 |
# File 'lib/appium_lib_core/element.rb', line 161 def save_screenshot(png_path) extension = File.extname(png_path).downcase if extension != '.png' ::Appium::Logger.warn 'name used for saved screenshot does not match file type. ' \ 'It should end with .png extension' end File.open(png_path, 'wb') { |f| f << screenshot_as(:png) } end |
#screenshot ⇒ Object
Return an element screenshot as base64
128 129 130 |
# File 'lib/appium_lib_core/element.rb', line 128 def screenshot bridge.element_screenshot @id end |
#screenshot_as(format) ⇒ Object
Return an element screenshot in the given format
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/appium_lib_core/element.rb', line 141 def screenshot_as(format) case format when :base64 bridge.element_screenshot @id when :png bridge.element_screenshot(@id).unpack('m')[0] else raise Core::Error::UnsupportedOperationError, "unsupported format: #{format.inspect}" end end |