Appium appium+python 定位日历控件中的元素时,可以找到该元素,点击后,日历控件未正确关闭,使用 tap,也未成功

沈丽君 · 2019年03月01日 · 最后由 沈丽君 回复于 2019年03月01日 · 1736 次阅读

测试环境:appium1.10.0+python 3.4
代码如下:

# 刷新界面
self.driver.find_element_by_id('picker').click()
sleep(2)
#self.driver.find_element_by_accessibility_id(u'返回今天').click()
el =getElementByName(self.driver,'返回今天')
sleep(3)
el.click()
x1=el.location['x']
y1=el.location['y']
width=el.size['width']
height=el.size['height']
x2=x1+width
y2=y1+height
self.driver.tap([(x1,y1),(x2,y2)],500)
sleep(5)
元素定位:

调用的定位方法代码:

def getElementByName(driver, name):
try:
el = driver.find_element_by_accessibility_id(name)
return el
except:
el = driver.find_element_by_android_uiautomator('new UiSelector().text("%s")'%name)
sleep(2)
return el
出现的问题:
使用了两种定位方式,debug 时皆未正确点击,请有解决过这类问题的指导一下,感激不尽:

共收到 3 条回复 时间 点赞

试下:driver.find_element_by_xpath(//*[@text='返回今天').click()

守护 回复

所有可能的定位我都试过,可以定位到这个元素,但是在点击后,界面上并没有点击结果(日期框关闭),界面也未加载数据

守护 回复

尝试使用 adb 定位,也是失败;

el =getElementByName(self.driver,'返回今天')
sleep(3)
#el.click()
x1=el.location['x']
y1=el.location['y']
width=el.size['width']
height=el.size['height']
x2=x1+width
y2=y1+height
x=int((x1+x2)/2)
y=int((y1+y2)/2)
os.popen("adb shell input tap"+ str(x) + " " +  str(y))
sleep(3)
4楼 已删除
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册