Skip to content

Instantly share code, notes, and snippets.

@DominikDary
Last active December 17, 2015 10:49
Show Gist options
  • Save DominikDary/5597616 to your computer and use it in GitHub Desktop.
Save DominikDary/5597616 to your computer and use it in GitHub Desktop.
private Element findElementByXpath(String expr, String source) throws Exception {
String xml = JsonXmlUtil.toXml(new JSONObject(source));
InputSource is = new InputSource(new StringReader(xml));
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression xpathExpr = xPath.compile(expr);
return (Element) xpathExpr.evaluate(is, XPathConstants.NODE);
}
{
"ref": 2131165195,
"l10n": {
"matches": 0
},
"displayed": false,
"name": "id/visibleTextView",
"value": "Text is sometimes displayed",
"shown": false,
"label": "null",
"type": "android.widget.TextView",
"rect": {
"origin": {
"y": 307,
"x": 126
},
"size": {
"width": 175,
"height": 19
}
}
@Test
public void testShouldBeAbleToFindHiddenElementAndGetShownState() throws Exception {
Element textView =
findElementByXpath("//TextView[@name='id/visibleTextView']", driver.getPageSource());
Assert.assertEquals(textView.getAttribute("shown"), "false");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment