金阳光。。。测试届的笑话了
#4 楼 @a3096556718 代码带上 markdown 格式。。编辑框右边自己点点看
@user1hod_screen_args()
def test_AA(self):
invest_list =accountPage.Account(self.driver)
username = login_cls[0][2]
password = login_cls[0][3]
logger.info('begin login app')
invest_list.click_tab_me()
loginButton = invest_list.is_element_exists(By.ID,u'com.yingzt.invest:id/summit_btn')
if loginButton:
login(self,username, password)
else:
pass
invest_list.click_my_invest()
sleep(2)
context = self.driver.contexts
self.driver.switch_to.context(u'WEBVIEW_com.yingzt.invest')
invest_list.click_invest_list()
sleep(2)
hh = self.driver.window_handles
sleep(2)
self.driver.switch_to_window(hh[1])
invest_list.click_invest_contract()
markdown 改下。。你这贴要被关小黑屋了
既然知道是 toast 的,在论坛搜搜看不就知道了
这帖子持续关注了,赞一个
mads 又把楼歪了😄
#4 楼 @johnwrite 控件层级问题。你点了文本,周围也可以点的
前排支持 q 博
#15 楼 @enumerate robotframework-appiumlibrary 是这样封装的:
def click_element(self, locator):
"""Click element identified by `locator`.
Key attributes for arbitrary elements are `index` and `name`. See
`introduction` for details about locating elements.
"""
self._info("Clicking element '%s'." % locator)
self._element_find(locator, True, True).click()
将 locator 参数(name=xxx,id=xxx)传入_element_find 方法定位元素
def _element_find(self, locator, first_only, required, tag=None):
application = self._current_application()
elements = self._element_finder.find(application, locator, tag)
if required and len(elements) == 0:
raise ValueError("Element locator '" + locator + "' did not match any elements.")
if first_only:
if len(elements) == 0: return None
return elements[0]
return elements
_element_finder 是 class ElementFinder 的实例,有如下定位策略
def __init__(self):
self._strategies = {
'identifier': self._find_by_identifier,
'id': self._find_by_id,
'name': self._find_by_name,
'xpath': self._find_by_xpath,
'class': self._find_by_class_name,
'accessibility_id': self._find_element_by_accessibility_id,
'android': self._find_by_android,
'ios': self._find_by_ios,
'css': self._find_by_css_selector,
None: self._find_by_default
}
通过_parse_locator(locator) 获取到定位策略和定位标准,调用 strategies 内定义的定位方法
def find(self, browser, locator, tag=None):
assert browser is not None
assert locator is not None and len(locator) > 0
(prefix, criteria) = self._parse_locator(locator)
strategy = self._strategies.get(prefix)
if strategy is None:
raise ValueError("Element locator with prefix '" + prefix + "' is not supported")
(tag, constraints) = self._get_tag_and_constraints(tag)
return strategy(browser, criteria, tag, constraints)
_parse_locator(locator) 对传入的定位策略 id=xxx,name=xxx 进行解析,=号前面的是定位方法,后面的是定位标准。
def _parse_locator(self, locator):
prefix = None
criteria = locator
if not locator.startswith('//'):
locator_parts = locator.partition('=')
if len(locator_parts[1]) > 0:
prefix = locator_parts[0].strip().lower()
criteria = locator_parts[2].strip()
return (prefix, criteria)
#11 楼 @enumerate def click_element(self,locator): 你是想要这样的封装吗?
挺好的入门帖,下次再被问这样的问题就直接贴你的帖子了😄有一点错误指出下啊
Android
Mac OSX 10.7+ or Windows 7+ or Linux
Android SDK ≥ 16 (SDK < 16 in Selendroid mode)
应该是 4.1 以下需要使用 selendroid 模式
@mads 快去