0

I am trying to access those properties in the following way:

def check_if_element_is_selected element
  if element.selected?
    return true
  else
    fail "The element is not selected"
  end
end

But I keep getting the following error:

undefined method `selected?' for nil:NilClass (NoMethodError)

Is there any other way to check these properties?

Wasiq Bhamla
  • 949
  • 1
  • 7
  • 12
  • Have you tried `element.attribute('checked')`? – Skizo-ozᴉʞS ツ Dec 13 '18 at 21:48
  • 1
    I don't know anything about Appium, but this can be caught by checking if `element` is [truthy](https://stackoverflow.com/q/23068834/3784008): `element && element.selected? ? (true) : (false)` – anothermh Dec 13 '18 at 23:28
  • The `element` is `nil`. You can't get an android property on it because it is not an android object. – sawa Dec 14 '18 at 10:11

1 Answers1

0

If you take a look on the Appium - Attribute documentation you can see that you can use the attribute function to get the attribute of your element.

In Ruby it should be like this:

ruby_lib example

find_element(:accessibility_id, 'SomeAccessibilityID').attribute("content-desc")

Also you can take a look on appium/ruby_lib where you can see that you can use

e.attribute('checked') # is the checkbox checked?

Community
  • 1
  • 1
Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
  • I tried using e.attribute('checked') but I keep getting the same error **undefined method `attribute' for nil:NilClass (NoMethodError)** // I'm using ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17] – catituh Dec 14 '18 at 17:13