mirror of
https://github.com/appium/appium.git
synced 2026-05-19 18:09:14 -05:00
Now possible to use resource-id for finding elements.
This commit is contained in:
@@ -388,16 +388,26 @@ public class Find extends CommandHandler {
|
||||
}
|
||||
break;
|
||||
case ID:
|
||||
try {
|
||||
text = apkStrings.getString(text);
|
||||
Logger.debug("Searching for text: " + text);
|
||||
} catch (final Exception e) { // JSONException and NullPointerException
|
||||
if (text.contains(":")) {
|
||||
// Handle this as a resource id
|
||||
sel = sel.resourceId(text);
|
||||
if (!many)
|
||||
sel = sel.instance(0);
|
||||
selectors.add(sel);
|
||||
// Don't fall through when using resource id
|
||||
break;
|
||||
} else {
|
||||
try {
|
||||
text = apkStrings.getString(text);
|
||||
Logger.debug("Searching for text: " + text);
|
||||
} catch (final Exception e) { // JSONException and NullPointerException
|
||||
|
||||
final StringWriter string = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(string));
|
||||
final StringWriter string = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(string));
|
||||
|
||||
throw new InvalidStrategyException("Unable to search by ID for "
|
||||
+ text + ".\n" + string.toString());
|
||||
throw new InvalidStrategyException("Unable to search by ID for "
|
||||
+ text + ".\n" + string.toString());
|
||||
}
|
||||
}
|
||||
// now fall through and do a name search
|
||||
case NAME:
|
||||
|
||||
@@ -122,6 +122,20 @@ describeWd('find element(s)', function(h) {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should find a single element by resource-id', function(done) {
|
||||
h.driver.elementById('android:id/home', function(err, element) {
|
||||
should.not.exist(err);
|
||||
should.exist(element.value);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should find multiple elements by resource-id', function(done) {
|
||||
h.driver.elementsById('android:id/text1', function(err, els) {
|
||||
should.not.exist(err);
|
||||
els.length.should.equal(11);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describeWd('find element(s) from element', function(h) {
|
||||
@@ -254,4 +268,4 @@ describeWd('mobile xmlKeyContains', function(h) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user