From 17a964fc19a4142a625b73a660acadbb52024994 Mon Sep 17 00:00:00 2001 From: Alex Kogon Date: Thu, 10 Sep 2015 14:52:43 +0200 Subject: [PATCH] always use text to match xpath --- src/org/synthuse/XpathManager.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/org/synthuse/XpathManager.java b/src/org/synthuse/XpathManager.java index c432b4f..9feb8ae 100644 --- a/src/org/synthuse/XpathManager.java +++ b/src/org/synthuse/XpathManager.java @@ -52,7 +52,8 @@ public class XpathManager implements Runnable{ @Override public void run() { - String results = buildXpathStatement(); + //@TODO (AJK) create separate action to use text mathing + String results = buildXpathStatement(true,50,50); events.executionCompleted(hwnd, results); } @@ -143,7 +144,22 @@ public class XpathManager implements Runnable{ parentTxtStr = " and @text='" + parentTxtStr + "'"; } if (!parentClassStr.isEmpty()) - builtXpath = "//win[@class='" + parentClassStr + "'" + parentTxtStr + "]/win[@class='" + classStr + "']"; + { + if (!txtStr.isEmpty()&&useFullTextMatching) { + if (txtStr.length() > maxTextLength) {// if the text is too long only test the first maxTextLength characters + txtStr = WindowsEnumeratedXml.escapeXmlAttributeValue(txtStr.substring(0, maxTextLength)); + txtStr = " and starts-with(@text,'" + txtStr + "')"; + } + else + txtStr = " and @text='" + txtStr + "'"; + builtXpath = "//win[@class='" + parentClassStr + "'" + parentTxtStr + "]/win[@class='" + classStr + "'" + txtStr + "]"; + } + else + { + builtXpath = "//win[@class='" + parentClassStr + "'" + parentTxtStr + "]/win[@class='" + classStr + "']"; + } + } + System.out.println(builtXpath); resultList = WindowsEnumeratedXml.evaluateXpathGetValues(xml, builtXpath); if (resultList.size() > 1) { // if there are still multiple results add position to the xpath int position = 1;