Class: Applitools::Selenium::Element
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Applitools::Selenium::Element
- Defined in:
- lib/applitools/selenium/element.rb
Constant Summary collapse
- JS_GET_COMPUTED_STYLE_FORMATTED_STR =
<<-JS.freeze var elem = arguments[0]; var styleProp = '%s'; if (window.getComputedStyle) { return window.getComputedStyle(elem, null) .getPropertyValue(styleProp); } else if (elem.currentStyle) { return elem.currentStyle[styleProp]; } else { return null; }; JS
- JS_GET_SCROLL_LEFT =
'return arguments[0].scrollLeft;'.freeze
- JS_GET_SCROLL_TOP =
'return arguments[0].scrollTop;'.freeze
- JS_GET_SCROLL_WIDTH =
'return arguments[0].scrollWidth;'.freeze
- JS_GET_SCROLL_HEIGHT =
'return arguments[0].scrollHeight;'.freeze
- JS_SCROLL_TO_FORMATTED_STR =
<<-JS.freeze arguments[0].scrollLeft = %d; arguments[0].scrollTop = %d; JS
- JS_GET_OVERFLOW =
'return arguments[0].style.overflow;'.freeze
- JS_SET_OVERFLOW_FORMATTED_STR =
"arguments[0].style.overflow = '%s'".freeze
- JS_SET_SCROLL_DATA_FORMATTED_STR =
"arguments[0].setAttribute('data-applitools-scroll', '%s')".freeze
- JS_SET_OVERFLOW_DATA_FORMATTED_STR =
"arguments[0].setAttribute('data-applitools-original-overflow', '%s')".freeze
- TRACE_PREFIX =
'EyesWebElement'.freeze
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #border_bottom_width ⇒ Object
- #border_left_width ⇒ Object
- #border_right_width ⇒ Object
- #border_top_width ⇒ Object
-
#bounds ⇒ Applitools::Base::Region
Gets the bounds of the element.
- #click ⇒ Object
- #computed_style(prop_style) ⇒ Object
- #computed_style_integer(prop_style) ⇒ Object
- #find_element(*args) ⇒ Object
- #find_elements(*args) ⇒ Object
-
#initialize(driver, element) ⇒ Element
constructor
Initialize class instance.
- #inspect ⇒ Object
- #overflow ⇒ Object
- #overflow=(overflow) ⇒ Object
- #overflow_data_attribute=(value) ⇒ Object
- #padding_bottom_width ⇒ Object
- #padding_left_width ⇒ Object
- #padding_right_width ⇒ Object
- #padding_top_width ⇒ Object
- #scroll_data_attribute=(value) ⇒ Object
- #scroll_height ⇒ Object
- #scroll_left ⇒ Object
- #scroll_to(location) ⇒ Object
- #scroll_top ⇒ Object
- #scroll_width ⇒ Object
-
#send_keys(keys) ⇒ Object
(also: #send_key)
Types content into text box.
- #to_hash ⇒ Object
Constructor Details
#initialize(driver, element) ⇒ Element
Initialize class instance.
41 42 43 44 45 |
# File 'lib/applitools/selenium/element.rb', line 41 def initialize(driver, element) super(element) @driver = driver end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
63 64 65 66 67 68 69 |
# File 'lib/applitools/selenium/element.rb', line 63 def ==(other) if other.is_a? self.class super other.web_element else super other end end |
#border_bottom_width ⇒ Object
160 161 162 |
# File 'lib/applitools/selenium/element.rb', line 160 def border_bottom_width computed_style_integer(:'border-bottom-width') end |
#border_left_width ⇒ Object
148 149 150 |
# File 'lib/applitools/selenium/element.rb', line 148 def border_left_width computed_style_integer(:'border-left-width') end |
#border_right_width ⇒ Object
156 157 158 |
# File 'lib/applitools/selenium/element.rb', line 156 def border_right_width computed_style_integer(:'border-right-width') end |
#border_top_width ⇒ Object
152 153 154 |
# File 'lib/applitools/selenium/element.rb', line 152 def border_top_width computed_style_integer(:'border-top-width') end |
#bounds ⇒ Applitools::Base::Region
Gets the bounds of the element.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/applitools/selenium/element.rb', line 87 def bounds point = location left = point.x top = point.y width = 0 height = 0 begin dimension = size width = dimension.width height = dimension.height rescue => e # Not supported on all platforms. Applitools::EyesLogger.error("Failed extracting size using JavaScript: (#{e.})") end if left < 0 width = [0, width + left].max left = 0 end if top < 0 height = [0, height + top].max top = 0 end Applitools::Region.new(left, top, width, height) end |
#click ⇒ Object
53 54 55 56 57 |
# File 'lib/applitools/selenium/element.rb', line 53 def click @driver.add_mouse_trigger(Applitools::MouseTrigger::MOUSE_ACTION[:click], self) # logger.info "click(#{bounds})"; web_element.click end |
#computed_style(prop_style) ⇒ Object
140 141 142 |
# File 'lib/applitools/selenium/element.rb', line 140 def computed_style(prop_style) driver.execute_script(JS_GET_COMPUTED_STYLE_FORMATTED_STR % prop_style, self).to_s end |
#computed_style_integer(prop_style) ⇒ Object
144 145 146 |
# File 'lib/applitools/selenium/element.rb', line 144 def computed_style_integer(prop_style) computed_style(prop_style).gsub(/px/, '').to_i.round end |
#find_element(*args) ⇒ Object
116 117 118 |
# File 'lib/applitools/selenium/element.rb', line 116 def find_element(*args) self.class.new driver, super end |
#find_elements(*args) ⇒ Object
120 121 122 |
# File 'lib/applitools/selenium/element.rb', line 120 def find_elements(*args) super(*args).map { |e| self.class.new driver, e } end |
#inspect ⇒ Object
59 60 61 |
# File 'lib/applitools/selenium/element.rb', line 59 def inspect TRACE_PREFIX + web_element.inspect end |
#overflow ⇒ Object
124 125 126 |
# File 'lib/applitools/selenium/element.rb', line 124 def overflow driver.execute_script(JS_GET_OVERFLOW, __getobj__).to_s end |
#overflow=(overflow) ⇒ Object
128 129 130 |
# File 'lib/applitools/selenium/element.rb', line 128 def overflow=(overflow) driver.execute_script(JS_SET_OVERFLOW_FORMATTED_STR % overflow, self) end |
#overflow_data_attribute=(value) ⇒ Object
136 137 138 |
# File 'lib/applitools/selenium/element.rb', line 136 def overflow_data_attribute=(value) driver.execute_script(JS_SET_OVERFLOW_DATA_FORMATTED_STR % value, self) end |
#padding_bottom_width ⇒ Object
176 177 178 |
# File 'lib/applitools/selenium/element.rb', line 176 def padding_bottom_width computed_style_integer(:'padding-bottom') end |
#padding_left_width ⇒ Object
164 165 166 |
# File 'lib/applitools/selenium/element.rb', line 164 def padding_left_width computed_style_integer(:'padding-left') end |
#padding_right_width ⇒ Object
168 169 170 |
# File 'lib/applitools/selenium/element.rb', line 168 def padding_right_width computed_style_integer(:'padding-right') end |
#padding_top_width ⇒ Object
172 173 174 |
# File 'lib/applitools/selenium/element.rb', line 172 def padding_top_width computed_style_integer(:'padding-top') end |
#scroll_data_attribute=(value) ⇒ Object
132 133 134 |
# File 'lib/applitools/selenium/element.rb', line 132 def scroll_data_attribute=(value) driver.execute_script(JS_SET_SCROLL_DATA_FORMATTED_STR % value, self) end |
#scroll_height ⇒ Object
192 193 194 |
# File 'lib/applitools/selenium/element.rb', line 192 def scroll_height Integer driver.execute_script(JS_GET_SCROLL_HEIGHT, self).to_s end |
#scroll_left ⇒ Object
180 181 182 |
# File 'lib/applitools/selenium/element.rb', line 180 def scroll_left Integer driver.execute_script(JS_GET_SCROLL_LEFT, self).to_s end |
#scroll_to(location) ⇒ Object
196 197 198 |
# File 'lib/applitools/selenium/element.rb', line 196 def scroll_to(location) driver.execute_script format(JS_SCROLL_TO_FORMATTED_STR, location.x, location.y), self end |
#scroll_top ⇒ Object
184 185 186 |
# File 'lib/applitools/selenium/element.rb', line 184 def scroll_top Integer driver.execute_script(JS_GET_SCROLL_TOP, self).to_s end |
#scroll_width ⇒ Object
188 189 190 |
# File 'lib/applitools/selenium/element.rb', line 188 def scroll_width Integer driver.execute_script(JS_GET_SCROLL_WIDTH, self).to_s end |
#send_keys(keys) ⇒ Object Also known as: send_key
Types content into text box.
76 77 78 79 80 81 |
# File 'lib/applitools/selenium/element.rb', line 76 def send_keys(*args) Selenium::WebDriver::Keys.encode(args).each do |key| @driver.add_text_trigger(self, key.to_s) end web_element.send_keys(*args) end |
#to_hash ⇒ Object
200 201 202 203 204 205 206 207 |
# File 'lib/applitools/selenium/element.rb', line 200 def to_hash { left: location.x.to_i, top: location.y.to_i, width: size.width.to_i, height: size.height.to_i } end |