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
"""
xpathStr = "//*["
keys = data.keys()
attribList = []
xpathStr = ""
attribLst = []
queryCount = 0
if "elm" in keys:
xpathStr = "//" + data["elm"] + "["
queryCount += 1
else:
xpathStr = "//" + data["elm"] + "["
if "id" in keys:
attribList.append("@id='" + data["id"] + "'")
queryCount += 1
if "class" in keys:
attribList.append("@class='" + data["class"] + "'")
queryCount += 1
if "type" in keys:
attribList.append("@type='" + data["type"] + "'")
queryCount += 1
if "value" in keys:
attribList.append("@value='" + data["value"] + "'")
queryCount += 1
flags = ["id", "class", "type", "value"]
for key in keys:
if key in flags:
attribLst.append("@" + data[key] + "='" + data[key] + "'")
queryCount += 1
if len(attribList) > 1:
xpathStr += " and ".join(attribList)
if len(attribLst) > 0:
xpathStr += " and ".join(attribLst)
else:
xpathStr += attribList[0]
xpathStr += attribLst[0]
xpathStr += "]"
self.logger.debug("Generated XPath: " + xpathStr)