Cleaned up xpath generation

This commit is contained in:
Maxim Stewart 2020-04-11 14:27:01 -05:00
parent 497cc522c7
commit 86bb7aaab2
1 changed files with 11 additions and 21 deletions

View File

@ -41,35 +41,25 @@ class ControlerMixin:
:return: created xpath string :return: created xpath string
""" """
xpathStr = "//*["
keys = data.keys() keys = data.keys()
attribList = [] attribLst = []
xpathStr = ""
queryCount = 0 queryCount = 0
if "elm" in keys: if "elm" in keys:
xpathStr = "//" + data["elm"] + "[" xpathStr = "//" + data["elm"] + "["
queryCount += 1
else:
xpathStr = "//" + data["elm"] + "["
if "id" in keys: flags = ["id", "class", "type", "value"]
attribList.append("@id='" + data["id"] + "'") for key in keys:
queryCount += 1 if key in flags:
if "class" in keys: attribLst.append("@" + data[key] + "='" + data[key] + "'")
attribList.append("@class='" + data["class"] + "'") queryCount += 1
queryCount += 1
if "type" in keys:
attribList.append("@type='" + data["type"] + "'")
queryCount += 1
if "value" in keys:
attribList.append("@value='" + data["value"] + "'")
queryCount += 1
if len(attribList) > 1:
xpathStr += " and ".join(attribList) if len(attribLst) > 0:
xpathStr += " and ".join(attribLst)
else: else:
xpathStr += attribList[0] xpathStr += attribLst[0]
xpathStr += "]" xpathStr += "]"
self.logger.debug("Generated XPath: " + xpathStr) self.logger.debug("Generated XPath: " + xpathStr)