Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h5Driver.isElementExist根据xpath获取元素,xpath expression 无效导致异常,api返回查找元素结果为True #24

Open
lan-tianyu opened this issue Nov 2, 2018 · 0 comments

Comments

@lan-tianyu
Copy link

代码部分,如下has_all_tab_cur 结果为true,实际看了日志才发现其实是没有找到元素的。

all_tab_xpath` = './/*[text()="所有订单"'
has_all_tab_cur = h5Driver.isElementExist(all_tab_xpath)

C:\Python27\Lib\site-packages\fastAutoTest\core\h5\h5Engine.py 方法 isElementExist 增加resultValueDict = self._networkHandler.send(getExistCmd).getResponse()[0]结果打印

        resultValueDict = self._networkHandler.send(getExistCmd).getResponse()[0]
        self.logger.debug("resultValueDict: {resultValueDict}".format(resultValueDict=resultValueDict))
        resultType = resultValueDict['result']['result']['subtype']
        num = 0
        while resultType == 'null' and num < 3:
            self.wait(WAIT_REFLESH_2_SECOND)
            getExistCmd = self._pageOperator.isElementExist(xpath, contextId)
            resultValueDict = self._networkHandler.send(getExistCmd).getResponse()[0]
            resultType = resultValueDict['result']['result']['subtype']
            num = num + 1
        return resultType != 'null'

日志:

[2018-11-02 18:21:12,907] [pid:5688] [h5Engine.py:478] [isElementExist] DEBUG: resultValueDict: {u'result': {u'exceptionDetails': {u'columnNumber': 53, u'exception': {u'className': u'DOMException', u'subtype': u'error', u'type': u'object', u'description': u'DOMException: Failed to execute \'evaluate\' on \'Document\': The string \'.//*[text()="\u6240\u6709\u8ba2\u5355"\' is not a valid XPath expression.\n    at <anonymous>:1:54', u'objectId': u'{"injectedScriptId":7,"id":2}'}, u'text': u'Uncaught', u'exceptionId': 1, u'scriptId': u'317', u'lineNumber': 0}, u'result': {u'className': u'DOMException', u'subtype': u'error', u'type': u'object', u'description': u'DOMException: Failed to execute \'evaluate\' on \'Document\': The string \'.//*[text()="\u6240\u6709\u8ba2\u5355"\' is not a valid XPath expression.\n    at <anonymous>:1:54', u'objectId': u'{"injectedScriptId":7,"id":1}'}}}
True

分析:
resultValueDict 返回结果的json数据如下,其中 resultValueDict['result']['result']['subtype']值为‘error’。源码中只判断了resultType != 'null',导致返回结果为true。使用者在未打开日志的场景下,并不知道自己的xpath expression 是错误的,还以为是找到了元素,这对结果的判断是不准确的。

{
	u 'result': {
		u 'exceptionDetails': {
			u 'columnNumber': 53,
			u 'exception': {
				u 'className': u 'DOMException',
				u 'subtype': u 'error',
				u 'type': u 'object',
				u 'description': u 'DOMException: Failed to execute \'evaluate\' on \'Document\': The string \'.//*[text()="\u6240\u6709\u8ba2\u5355"\' is not a valid XPath expression.\n    at <anonymous>:1:54',
				u 'objectId': u '{"injectedScriptId":7,"id":2}'
			},
			u 'text': u 'Uncaught',
			u 'exceptionId': 1,
			u 'scriptId': u '317',
			u 'lineNumber': 0
		},
		u 'result': {
			u 'className': u 'DOMException',
			u 'subtype': u 'error',
			u 'type': u 'object',
			u 'description': u 'DOMException: Failed to execute \'evaluate\' on \'Document\': The string \'.//*[text()="\u6240\u6709\u8ba2\u5355"\' is not a valid XPath expression.\n    at <anonymous>:1:54',
			u 'objectId': u '{"injectedScriptId":7,"id":1}'
		}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant