Reputation: 1
I am trying to use xpath in RFT. Searching over the net threw this code at me-
private static NodeList getNodesWithXPath(Document document, String xpathStr)
throws XPathExpressionException {
NodeList nodes = null;
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
if (xpathStr != null) {
XPathExpression expr = xpath.compile(xpathStr);
Object result = expr.evaluate(document, XPathConstants.NODESET);
nodes = (NodeList) result;
}
return nodes;
}
Now, I am new at RFT and totally at a loss about how to access the 'Document' object? Trying to typecast TestObject into this throws an exception. I could see a few examples stating something like
Document doc = parse(xmlFileLocation)
but I am not sure what this xmlFileLocation means. I have a simple web page where I need to identify the element using xpath.
P.S. - I understand there are other ways of identifying the object using atDescendant, etc, but I need to explicitly use xpath here due to some reasons.
Any help would be greatly appreciated.
Thanks!
Upvotes: 0
Views: 440
Reputation: 4695
They are different Document
objects.
I think you got the code from IBM developerworks, and that is a document obtained from an XML file, thus browsable with XPATH.
RFT Document is com.rational.test.ft.object.interfaces.DocumentTestObject
while XML related one probably is org.w3c.dom.Document
.
Totally different classes.
XPath is not supported by RFT and also no answers in the forums.
If you need XPath queries in your pages try something else, like Selenium.
Upvotes: 1