Finding element by name on android in Appium 1.6.3

We are trying to move from Appium 1.4.13 to 1.6.3 on Android

One of the biggest problems we are having is finding elements. :uiautomator is no longer a supported method by which to search (even though the code is there deeper in the stack). :name is no longer supported. I’d rather not convert everything to xpath, but I don’t see any alternative yet.

2 Likes

Here is what I came up with using xpath:

def find_element_by_name(text)
  driver.find_element(:xpath, "//*[@content-desc='#{text}']|//*[@text='#{text}']")
end

I am trying to preserve the previous behavior, so this finds matching text or content description. I’ve also created my own methods, find_element_by_text and find_element_by_desc. My xpath is not the strongest, so I’m happy to take any suggestions for improvement.

scroll_to still doesn’t work reliably. It works inside my app, but not on an Android Settings page. There have been a number of questions about getting scroll_to to work along with suggestions as to how. I’ll post my solution in another thread for those interested. I apologize in advance to all of you who aren’t using Ruby.

we do not have problem with move with:

// IOS
// replace of srollTo
        JavascriptExecutor js = (JavascriptExecutor) driver;
        HashMap scrollObject = new HashMap<>();
        scrollObject.put("predicateString", "value == '" + text + "'");
        js.executeScript("mobile: scroll", scrollObject);

// replace of search by name. instead "value" attribute may use any needed.
        WebElement el = ((IOSDriver) driver).findElementByIosNsPredicate("value = '" + text + "'");
        return tapElement((MobileElement) el);


// Android
// scroll and tap
tapElement(driver.findElement(MobileBy
                .AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                        + "new UiSelector().text(\""+descr+"\"));")));
// to search by content-description property
// "new UiSelector().text(\""+descr+"\"));"))); -> "new UiSelector().description(\""+descr+"\"));")));

latest beta 1.6.4 appium and java 5.X beta client

Now that’s strange. I had been able to use find_element(:uiautomator, ui_selector_string) in appium 1.4.13, but it doesn’t work now. I’ll keep digging

use driver.findElement(MobileBy.accessibilityID(“text/contentDesc”))

An Appium developer suggested using find_element_by_appium(:uiautomator, …). I have not yet tried it (I was working on my workaround), but he suggested I could replace all calls to find_element to find_element_by_appium.

See https://github.com/appium/ruby_lib/issues/527#issuecomment-291687471 for more details