Now possible to use resource-id for finding elements.

This commit is contained in:
Felix Angerborn
2013-08-28 12:18:07 +02:00
parent 4ddae6e3f1
commit 5cdc090cc2
2 changed files with 33 additions and 9 deletions
@@ -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:
+15 -1
View File
@@ -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();
});
});
});
});