module WDA::FindElement

Public Instance Methods

accessibility_id(value) click to toggle source

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
accessibility_ids(value) click to toggle source

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
button(value = 0) click to toggle source

Find button by given index or value @param value [String, Integer] If value is integer then return the button at that index If value is string then return the first button which contains given value @return [Hash, Element]

# File lib/wda_lib/find_element.rb, line 210
def button(value = 0)
  if value.is_a? Numeric
    finds(:xpath, "//XCUIElementTypeButton")[value]
  else
    find(:xpath, "//XCUIElementTypeButton[@name=\"#{value}\"]")
  end
end
buttons(value = nil) click to toggle source

Find buttons by given index or value @param value [String, Integer] If value is integer then return the all buttons If value is string then return the all buttons which contain given value @return [Array] All found buttons

# File lib/wda_lib/find_element.rb, line 223
def buttons(value = nil)
  if value.nil?
    finds(:xpath, "//XCUIElementTypeButton")
  else
    finds(:xpath, "//XCUIElementTypeButton[@name=\"#{value}\"]")
  end
end
class_name(value) click to toggle source

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
class_names(value) click to toggle source

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(type, value) click to toggle source

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
find_element(*args) click to toggle source
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(*args) click to toggle source

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_subl_element(id, type, value) click to toggle source

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_subl_elements(id, type, value) click to toggle source

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
finds(type, value) click to toggle source

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
first_button() click to toggle source

Find the first Button @return [Hash] button

# File lib/wda_lib/find_element.rb, line 233
def first_button
  finds(:xpath, "//XCUIElementTypeButton").first
end
first_textfield() click to toggle source

Find the first TextField. @return [TextField]

# File lib/wda_lib/find_element.rb, line 271
def first_textfield
  finds(:xpath, "//XCUIElementTypeTextField").first
end
icon(value = 0) click to toggle source

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
icons(value = nil) click to toggle source

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
id(value) click to toggle source

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
ids(value) click to toggle source

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
last_button() click to toggle source

Find the last Button @return [Hash] button

# File lib/wda_lib/find_element.rb, line 239
def last_button
  finds(:xpath, "//XCUIElementTypeButton").last
end
last_textfield() click to toggle source

Find the last TextField. @return [TextField]

# File lib/wda_lib/find_element.rb, line 277
def last_textfield
  finds(:xpath, "//XCUIElementTypeTextField").last
end
name(value) click to toggle source

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
names(value) click to toggle source

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
partial_text(value) click to toggle source

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
partial_texts(value) click to toggle source

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
predicate_text(predicate_value) click to toggle source

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
predicate_texts(predicate_value) click to toggle source

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
searchfield(value = 0) click to toggle source

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
searchfields(value = nil) click to toggle source

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
secure_textfield(value = 0) click to toggle source

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
secure_textfields() click to toggle source

Find the all SecureTextField. @return [Array]

# File lib/wda_lib/find_element.rb, line 296
def secure_textfields 
  finds(:xpath, "//XCUIElementTypeSecureTextField")
end
set_timeout(second) click to toggle source
# File lib/wda_lib/find_element.rb, line 407
def set_timeout(second)
  @timeout = second
end
statictext(value = 0) click to toggle source

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
statictexts(value = nil) click to toggle source

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
stringlize(instring) click to toggle source

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
text(value) click to toggle source

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
textfield(value = 0) click to toggle source

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
textfields(value = nil) click to toggle source

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
texts(value) click to toggle source

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
visible_cell(id) click to toggle source

@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
xpath(value) click to toggle source

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