Hi,
I’m facing an issue in retrieving an specific element attribute xml from the provided xml.
Example
In the login page I want the xml of only username and password fields. But the login page contains username, password, sign in button, remember me radio button, forgot password link
I’m able to retrieve the login page xml using “driver.getPageSource();”. Base on this xml I’m trying to to get the username and password field xml
DocumentBuilderFactory xmlFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = xmlFactory.newDocumentBuilder();
Document xmlDoc = docBuilder.parse("/Users/c5247941/Desktop/Login.xml");
xmlDoc.getDocumentElement().normalize();
XPathFactory xpathFact = XPathFactory.newInstance();
XPath xpath = xpathFact.newXPath();
try( PrintWriter out = new PrintWriter("/Users/test/Desktop/testing.xml" ) ){
out.println( text123 );
}
catch (Exception e) {
System.out.println(e);
}
XPathExpression expr = xpath.compile("/AppiumAUT/UIAApplication/UIAWindow[1]/UIAScrollView/UIATextField[@value and string-length(@value)!=0]");
NodeList nl = (NodeList) expr.evaluate(xmlDoc, XPathConstants.NODESET);
for (int i = 0; i < nl.getLength(); i++)
{
Element el = (Element) nl.item(i);
System.out.println("Second output"+el.getTextContent().toString());
try( PrintWriter out = new PrintWriter( "/Users/test/Desktop/Testcreate.xml" ) ){
out.println( el );
}
catch (Exception e) {
System.out.println(e);
}
Output
Second output(with three lines of empty space) like
[TestNG] Running:
/private/var/folders/jv/yrryxtp5505bb_j58kd9bl0r7gv33v/T/testng-eclipse–444050191/testng-customsuite.xml
Second output
PASSED: tests
PASSED: launchPad
Thanks in advance