Unable to find any text field beyond the first text field in a tableview

I’m working on an iPad app in the iPad 2 simulator, iOS 8.1, Appium 1.3.4

Part of the app I’m automating has a series of text fields in a table view for adding your home address. While in the new address view, page :UIATextfield brings up this list:

[3] pry(main)> page :UIATextField
get /context
get /context
post /execute
{
    :script => "UIATarget.localTarget().frontMostApp().windows()[0].getTree()"
}
post /appium/app/strings
UIATextField
   name, label, value: Full Name
UIATextField
   name, label, value: Full Name
UIATextField
   name, label: Address Line 1
   value: Street Address Line 1
   id: add => Add
UIATextField
   name, label: Address Line 2
   value: Street Address Line 2
   id: add => Add
UIATextField
   name, label, value: City
UIATextField
   name, label, value: State
UIATextField
   name, label: ZIP Code
   value: ZIP
UIATextField
   name, label, value: Phone
nil

I can find the first text field just fine using textfield(“Full Name”)

[12] pry(main)> textfield("Full Name")
post /element
{
    :using => "xpath",
    :value => "//UIATextField[@visible=\"true\" and (contains(translate(@name,\"FULL NAME\",\"full name\"), \"full name\") or contains(translate(@hint,\"FULL NAME\",\"full name\"), \"full name\") or contains(translate(@label,\"FULL NAME\",\"full name\"), \"full name\") or contains(translate(@value,\"FULL NAME\",\"full name\"), \"full name\"))] | //UIASecureTextField[@visible=\"true\" and (contains(translate(@name,\"FULL NAME\",\"full name\"), \"full name\") or contains(translate(@hint,\"FULL NAME\",\"full name\"), \"full name\") or contains(translate(@label,\"FULL NAME\",\"full name\"), \"full name\") or contains(translate(@value,\"FULL NAME\",\"full name\"), \"full name\"))]"
}
 Selenium::WebDriver::Element:0x..fba3133b09f2b1408 id=4

I can’t, however, find any subsequent textfields. Here is textfield(“Address Line 1”)

    [13] pry(main)> textfield("Address Line 1")
    post /element
    {
        :using => "xpath",
        :value => "//UIATextField[@visible=\"true\" and (contains(translate(@name,\"ADDRESS LINE 1\",\"address line 1\"), \"address line 1\") or contains(translate(@hint,\"ADDRESS LINE 1\",\"address line 1\"), \"address line 1\") or contains(translate(@label,\"ADDRESS LINE 1\",\"address line 1\"), \"address line 1\") or contains(translate(@value,\"ADDRESS LINE 1\",\"address line 1\"), \"address line 1\"))] | //UIASecureTextField[@visible=\"true\" and (contains(translate(@name,\"ADDRESS LINE 1\",\"address line 1\"), \"address line 1\") or contains(translate(@hint,\"ADDRESS LINE 1\",\"address line 1\"), \"address line 1\") or contains(translate(@label,\"ADDRESS LINE 1\",\"address line 1\"), \"address line 1\") or contains(translate(@value,\"ADDRESS LINE 1\",\"address line 1\"), \"address line 1\"))]"
    }
    Selenium::WebDriver::Error::NoSuchElementError: 
    from /Users/username/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'

Just to confirm, here’s the array returned when I try textfields

[15] pry(main)> textfields
post /elements
{
    :using => "xpath",
    :value => "//UIATextField[@visible=\"true\"] | //UIASecureTextField[@visible=\"true\"]"
}
[
    [0] #<Selenium::WebDriver::Element:0x..fbf3aa72fd4cd4c9a id="6">
]

textfields only finds one element, but page :UIATextField returns all of them with their labels and names. This affects not only this screen, but any screen that has multiple text fields (i.e. new account, login page)

Here’s the appium server logs from the above commands run in order: textfield_logs.txt (239.7 KB)

You could try the master version of appium_lib to see if that’s better. The problem is most likely related to xpath bugs.

I installed the gem from the git you linked. I’m having essentially the same results, but with a different error message this time. When I try textfield(“Address Line 1”) I now get this:

Selenium::WebDriver::Error::NoSuchElementError: An element could not be located on the page using the given search parameters.
from /Users/username/.rvm/gems/ruby-2.1.1/gems/appium_lib-4.1.0/lib/appium_lib/common/helper.rb:220:in `_no_such_element'

I tried _by_json({typeArray: [“UIATextField”], onlyFirst: false, onlyVisible: false}) and it returns all the elements:

[18] pry(main)> _by_json({typeArray: ["UIATextField"], onlyFirst: false, onlyVisible: false})
post /execute
{
    :script => "        (function() {\n        var opts = {\"typeArray\":[\"UIATextField\"],\"onlyFirst\":false,\"onlyVisible\":false}\n\n        return $.mainWindow()._elementOrElementsByType(opts);\n        })();\n"
}
[
    [0] #<Selenium::WebDriver::Element:0x..f9ba60d402718037a id="13">,
    [1] #<Selenium::WebDriver::Element:0x..fdf36c556ae67575a id="14">,
    [2] #<Selenium::WebDriver::Element:0x3c1441784a32e570 id="15">,
    [3] #<Selenium::WebDriver::Element:0x40adda2868701c42 id="16">,
    [4] #<Selenium::WebDriver::Element:0x..fab44272a29eb2d80 id="17">,
    [5] #<Selenium::WebDriver::Element:0x..fd4131fa9e8f5194a id="18">,
    [6] #<Selenium::WebDriver::Element:0x..f9599eb7addbfd04 id="19">
]

I still can’t .send_keys to these elements using the array returned because any text field after the first comes up as not visible.

Selenium::WebDriver::Error::JavascriptError: target.frontMostApp().mainWindow().elements()[24].elements()[1].elements()[0] could not be tapped because the element is not visible
from /Users/username/.rvm/gems/ruby-2.1.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'

These textfields are visibile in the appium inspector. I am able to send_keys after tapping on the text field first, though. But only by using the xpath with find_element

I reproduced the problem using appium’s uicatalog iOS test app. I recommend opening an issue on GitHub. The problem isn’t specific to Ruby as far as I can tell.

Ok. I opened an issue.