module WDA::FindElement
Public Instance Methods
Search with given accessibility_id
@param value [String] @return [Hash]
# File lib/wda_lib/find_element.rb, line 112 def accessibility_id(value) find :accessibility_id, value end
Search all element with given accessibility_id
@param value [String] @return [Array]
# File lib/wda_lib/find_element.rb, line 119 def accessibility_ids(value) finds :accessibility_id, value end
Search with class name @param value [String] XCUIElementType*, class name in XCUITest, ex: class_names
('Button') to search XCUIElementTypeButton @return [Hash] found XCUIElementType* elements
# File lib/wda_lib/find_element.rb, line 154 def class_name(value) find :class_name, match(value) end
Search with class name @param value [String] XCUIElementType*, class name in XCUITest, ex: class_names
('Button') to search XCUIElementTypeButton @return [Array] contains all XCUIElementType* elements
# File lib/wda_lib/find_element.rb, line 161 def class_names(value) finds :class_name, match(value) end
Find element with given type and value, return first found element @param type [String, Symbol], value [Stirng] @return [Hash]
# File lib/wda_lib/find_element.rb, line 12 def find(type, value) wait = Wait.new(:timeout => @timeout) # seconds begin wait.until { @element = post('/element', { using: stringlize(type), value: value }) @element['status'] == 0 } ensure raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @element['status'] != 0 end Element.new self, @element['value'] end
This is calling selenium find_element* methods##########
Find element with given type and value, return first found element @param args [*args] @return [Object]
# File lib/wda_lib/find_element.rb, line 382 def find_element(*args) @driver.find_element(*args) end
Find elements with given type and value, return in an Array @param args [*args] @return [Array<Element>]
# File lib/wda_lib/find_element.rb, line 389 def find_elements(*args) @driver.find_elements(*args) end
Find child element by given type and value, return first found element @param id [String] parent element id, type [String, Symbol], value [Stirng] @return [Object] found element
# File lib/wda_lib/find_element.rb, line 48 def find_subl_element(id, type, value) wait = Wait.new(:timeout => @timeout) # seconds begin wait.until { @element = post('/element/' + id + '/element', { using: stringlize(type), value: value }) @element['status'] == 0 } ensure raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @element['status'] != 0 end Element.new self, @element['value'] end
Find children elements by given type and value, return elements array @param id [String] parent element id, type [String, Symbol], value [Stirng] @return [Array<Element>]
# File lib/wda_lib/find_element.rb, line 65 def find_subl_elements(id, type, value) wait = Wait.new(:timeout => @timeout) # seconds begin wait.until { @result = post('/element/' + id + '/elements', { using: stringlize(type), value: value }) @elements = @result['value'] @result['status'] != 7 } ensure raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @result['status'] != 0 end @elements.map { |element| Element.new self, element } end
Find all elements with given type and value, return in an Array @param type [String, Symbol], value [Stirng] @return [Array]
# File lib/wda_lib/find_element.rb, line 30 def finds(type, value) wait = Wait.new(:timeout => @timeout) # seconds begin wait.until { @elements = post('/elements', { using: stringlize(type), value: value })['value'] @elements.length != 0 } ensure raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @elements.length == 0 end @elements.map { |element| Element.new self, element } end
Find the first TextField. @return [TextField]
# File lib/wda_lib/find_element.rb, line 271 def first_textfield finds(:xpath, "//XCUIElementTypeTextField").first end
Find icon by given index or value @param value [String, Integer] If value is integer then return the icon at that index If value is string then return the first icon which contains given value @return [Hash, Element]
# File lib/wda_lib/find_element.rb, line 331 def icon(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeIcon")[value] else find(:xpath, "//XCUIElementTypeIcon[@name=\"#{value}\"]") end end
Find icons by given index or value @param value [String] If value is integer then return all icons If value is string then return the all icons which contain given value @return [Array] All found icons
# File lib/wda_lib/find_element.rb, line 344 def icons(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeIcon") else finds(:xpath, "//XCUIElementTypeIcon[@name=\"#{value}\"]") end end
Search with given id @param value [String] @return [Hash]
# File lib/wda_lib/find_element.rb, line 98 def id(value) find :id, value end
Search all element with given id @param value [String] @return [Array]
# File lib/wda_lib/find_element.rb, line 105 def ids(value) finds :id, value end
Find the last TextField. @return [TextField]
# File lib/wda_lib/find_element.rb, line 277 def last_textfield finds(:xpath, "//XCUIElementTypeTextField").last end
Search with given name @param value [String] @return [Hash]
# File lib/wda_lib/find_element.rb, line 84 def name(value) find :name, value end
Search all element with given name @param value [String] @return [Array]
# File lib/wda_lib/find_element.rb, line 91 def names(value) finds :name, value end
Search with given partial value (partial link text) @param value [String] @return [Hash]
# File lib/wda_lib/find_element.rb, line 140 def partial_text(value) find :partial_link_text, "label=#{value}" end
Search with given partial value (partial link text) @param value [String] @return [Array]
# File lib/wda_lib/find_element.rb, line 147 def partial_texts(value) finds :partial_link_text, "label=#{value}" end
Search predicate string, return first found element @param predicate_value [String] 'isWDVisible=1' example: 'isWDAccessible=1', 'isWDEnabled=0' @return [Hash]
# File lib/wda_lib/find_element.rb, line 188 def predicate_text(predicate_value) find :predicate_string, predicate_value end
Search with predicate string @param predicate_value [String] 'isWDVisible=1' example: 'isWDAccessible=1', 'isWDEnabled=0', 'isWDAccessibilityContainer=1' @return [Array]
# File lib/wda_lib/find_element.rb, line 196 def predicate_texts(predicate_value) finds :predicate_string, predicate_value end
Find SearchField by given index or value @param value [String, Integer] If value is integer then return the SearchField at that index If value is string then return the first SearchField which has given value as name @return [Hash, Element]
# File lib/wda_lib/find_element.rb, line 357 def searchfield(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeSearchField")[value] else find(:xpath, "//XCUIElementTypeSearchField[@name=\"#{value}\"]") end end
Find icons by given index or value @param value [String] If value is integer then return all SearchFields If value is string then return the all SearchFields which have given value as name @return [Array] All found SearchFields
# File lib/wda_lib/find_element.rb, line 370 def searchfields(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeSearchField") else finds(:xpath, "//XCUIElementTypeSearchField[@name=\"#{value}\"]") end end
Find secure_textfield
by given index or value @param value [String, Integer] If value is integer then return the secure_textField at that index If value is string then return the first secure_textField which contains given value @return [TextField]
# File lib/wda_lib/find_element.rb, line 286 def secure_textfield(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeSecureTextField")[value] else find(:xpath, "//XCUIElementTypeSecureTextField[@value=\"#{value}\"]") end end
Find the all SecureTextField. @return [Array]
# File lib/wda_lib/find_element.rb, line 296 def secure_textfields finds(:xpath, "//XCUIElementTypeSecureTextField") end
# File lib/wda_lib/find_element.rb, line 407 def set_timeout(second) @timeout = second end
Find StaticText by given index or value @param value [String, Integer] If value is integer then return the StaticText at that index If value is string then return the first StaticText which contains given value @return [TextField]
# File lib/wda_lib/find_element.rb, line 305 def statictext(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeStaticText")[value] else find(:xpath, "//XCUIElementTypeStaticText[@value=\"#{value}\"]") end end
Find the all StaticText. @param value [String] If value is integer then return all StaticTexts If value is string then return the all StaticTexts which contain given value @return [Array]
# File lib/wda_lib/find_element.rb, line 318 def statictexts(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeStaticText") else finds(:xpath, "//XCUIElementTypeStaticText[@value=\"#{value}\"]") end end
Turn symbol to string, replace '_' to ' ' @param instring [Symbol] @return [String]
# File lib/wda_lib/find_element.rb, line 397 def stringlize(instring) if instring.is_a? Symbol instring.to_s.gsub('_', ' ') elsif instring.is_a? String return instring.gsub('_', ' ') else fail 'Xpath searching type should be a String' end end
Search with given value (Complete value) @param value [String] @return [Hash]
# File lib/wda_lib/find_element.rb, line 126 def text(value) find :link_text, "label=#{value}" end
Find textfield by given index or value @param value [String, Integer] If value is integer then return the textField at that index If value is string then return the first textField which contains given value @return [TextField]
# File lib/wda_lib/find_element.rb, line 248 def textfield(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeTextField")[value] else find(:xpath, "//XCUIElementTypeTextField[@value=\"#{value}\"]") end end
Find the all TextField. @param value [String] If value is integer then return all textFields If value is string then return all textFields which contain given value @return [Array]
# File lib/wda_lib/find_element.rb, line 261 def textfields(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeTextField") else finds(:xpath, "//XCUIElementTypeTextField[@value=\"#{value}\"]") end end
Search with given value (Complete value) @param value [String] @return [Array]
# File lib/wda_lib/find_element.rb, line 133 def texts(value) finds :link_text, "label=#{value}" end
@return element's visible cells [Array]
# File lib/wda_lib/find_element.rb, line 201 def visible_cell(id) get '/wda/element/' + id + '/getVisibleCells' end
Search with xpath @param value [String] example: “//XCUIElementTypeButton”, “//XCUIElementTypeTextField” @return [Array] contains all elements which match given xpath
# File lib/wda_lib/find_element.rb, line 171 def xpath(value) finds :xpath, value end
Xpath search with element type, element attribute, element attribute value @param type [String], attribute [String], value [String] example: xpath('Button', 'name', 'Share') for “//XCUIElementTypeButton” @return [Array] contains all elements which match given variables
# File lib/wda_lib/find_element.rb, line 180 def xpath_search(type, attribute, value) finds :xpath, "//#{match(type)}[@#{attribute}=\"#{value}\"]" end