Undefined method Click

Hello there,

I’m totally new to Appium.
I have used Appium Desktop to record a scenario on iOS.
Appium Desktop generate some code which looks like :
require ‘rubygems’
require ‘appium_lib’

caps = {}
caps["platformName"] = "iOS"
caps["deviceName"] = "iPhone Simulator"
caps["platformVersion"] = "11.0"
caps["bundleId"] = "[bundleIdOfMyApp]"
opts = {
    sauce_username: nil,
    server_url: "http://localhost:4723/wd/hub"
}

driver = Appium::Driver.new({caps: caps, appium_lib: opts}, true).start_driver

el1 = driver.find_elements(:accessibility_id, "[Name_of_element]")
el1.click

driver.quit

I assume that this code launch the application and perform a clic.
When I try “ruby [name_of_file]”, the application launches, but I have the following error : <main>': undefined methodclick’ for #Array:0x00007f (NoMethodError)

I am missing something ?
Appium-doctor says that everything looks good.

Thanks for your help

find_elements will always return an array, and as the error says, the object array does not have a click method. You’ll need to either iterate through the array, or use ‘find_element’ if there is only one.

Here’s a link to an article about iterating through an array in Ruby:

1 Like

Thanks you for your quick answer :slight_smile:

With a loop on this array, I am able to perform my clic ! (I will take a look after to find_element if there is only one element which is probably the case)

Now I have some trouble to perform a tap on non accessibility element, but I will search !

Thanks you again