环境:
appium1.10.0
xcode 10.1
pytest 3.5.0

例子:
控件定义:sousuo_btn = page_element(accessibility_id="HXSearchStockView")

if public_page.sousuo_btn :
public_page.sousuo_btn.click()
else:
.......

假设 sousuo_btn 定义正确,当元素存在该页面时,则点击动作能跑成功,但是如果页面不存在 sousuo_btn 控件时,则会直接在 page_element 方法内报错 (信息如下),不走 else 语句,
求解决!!!
page_object/appium_page_objects.py:92: in get
return self.find(context)
page_object/appium_page_objects.py:79: in find
return context.find_element(*self.locator)
../../Library/Python/2.7/lib/python/site-packages/appium/webdriver/webdriver.py:220: in find_element
'using': by,'value': value})['value']
../../Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/webdriver.py:201: in execute
self.error_handler.check_response(response)
../../Library/Python/2.7/lib/python/site-packages/appium/webdriver/errorhandler.py:24: in check_response
super(MobileErrorHandler, self).check_response(response)


↙↙↙阅读原文可查看相关链接,并与作者交流