Appium 求助,在微信下测试 webview 项目报如下错误,已打开 TBS 内核 Inspector 调试功能,百度过也没找到原因,倒腾几天了,麻烦知道的大神指导一下。

vic · 2017年04月07日 · 最后由 王乐新 回复于 2017年05月05日 · 1602 次阅读

脚本如下:


from appium import webdriver
import time

packageName='com.tencent.mm'
appActivity='.ui.LauncherUI'

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = 'ZX1G2293B6'
desired_caps['appPackage'] = packageName
desired_caps['appActivity'] = appActivity
desired_caps['fullReset'] = 'false'
desired_caps['unicodeKeyboard'] = 'True'
desired_caps['resetKeyboard'] = 'True'
desired_caps['fastReset'] = 'false'

desired_caps['chromeOptions']={'androidProcess': 'com.tencent.mm:tools'}  

driver = webdriver.Remote('http://127.0.1.1:4723/wd/hub', desired_caps)

#driver.implicitly_wait(30)
driver.find_element_by_name('我').click()
print (driver.current_context)
driver.find_element_by_name('相册').click()

driver.find_element_by_xpath("//*[contains(@text,'炒股难就用股先生,【Vic66】邀请您一起使用股先生。')]").click()
print (driver.current_context)
driver.find_element_by_xpath("//*[contains(@text,'炒股难就用股先生,【Vic66】邀请您一起使用股先生。')]").click()
print (driver.current_context)
driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
print (driver.current_context)
print (切换ok)
time.sleep(10)
print (driver.page_source)
#点击菜单
driver.find_element_by_id("showMenuIocn").click()
print (driver.current_context)
#点击登录
driver.find_element_by_css_selector("button.login").click()
print (driver.current_context)
driver.find_element_by_css_selector("input.mui-input-clear").clear()
print (driver.current_context)
driver.find_element_by_css_selector("input.mui-input-clear").send_keys("18681378808")
print (driver.current_context)
driver.find_element_by_css_selector("div.mui-input-row.password > input.mui-input-clear").clear()
print (driver.current_context)
driver.find_element_by_css_selector("div.mui-input-row.password > input.mui-input-clear").send_keys("123456")
driver.find_element_by_css_selector("button").click()

driver.switch_to_default_content()

time.sleep(2)
driver.quit()

log 日志如下:

共收到 17 条回复 时间 点赞

楼主上茶,坐等大神回复

webview 的 context name 名称错了,你确定是你写的那个

vic #15 · 2017年04月09日 Author
辣么丑 回复

大神能说得明白一点吗?你是指这个报错吗?我也找过对应原因,参考的https://testerhome.com/topics/7812这个帖子,但是还是没有解决这个问题。

确定一下 Android 版本,你修改了 android-hybrid.js 文件(针对 Android 6.0+)然后打印一下 context 看看都用什么内容,修改了 context 应该就没有 undefined 了

vic #13 · 2017年04月12日 Author
太阳糖 回复

非常感谢给的思路,发现我的设备系统是 6.0.1,脚本是 6.0,但是改正之后又有如下错误,在百度找了些资料发现还是没有头绪,大神能帮忙看下吗?

把这句话 desired_caps['chromeOptions']={'androidProcess': 'com.tencent.mm:tools'}
改成 desired_caps['chromeOptions']={'androidProcess' = 'com.tencent.mm:tools'}
试试
你的错误提示是不能解析 chromeOptions

vic #11 · 2017年04月13日 Author
太阳糖 回复

谢谢你啊,问题终于解决了,出现上面的报错主要还是 chromedriver 的版本问题导致的,最开始也考虑到这个问题,但换了版本依然存在,原因是我版本号和 chrome 版本不对应,走了不少弯路。
https://testerhome.com/topics/6954
这个帖子看了几遍,各种尝试,最终试出原因
http://www.cnblogs.com/testervic/p/6705159.html
这个贴是 chromedriver 的对应版本下载地址。后来人少走弯路

@test469858846 你这个对应表格 详细,我之前都是 都是从最高版往下试,大家共同学习进步

@test469858846 请问你用的微信版本是多少?对应的 chromedriver 呢?

vic 回复

请教下,我这边运行的代码和你差不多。但是切换到 webview 的时候成功了,但是后面的 findelementbyxpath.click 没有响应点击事件但是又没有报错,你遇到过这种情况吗

vic #7 · 2017年05月05日 Author
王乐新 回复

不好意思回复晚了,没有点击你看是不是没定位上,或者换一种方式定位,webview 定位可以再 chrome 用 F12 工具去看下元素,或者用最简单的 selenium ide 直接录制 copy 过来即可

vic #6 · 2017年05月05日 Author
渐次消逝 回复

chrome 版本可以再 pc 上用 chrome 浏览器的 chrome://inspect/#devices 工具来查看对应的版本

vic 回复

定位是定位上了,用 .text 也可以拿到里面的值,怀疑可能 H5 开发调用的别的点击方法导致的。我用另外一种方法已经解决了。
如果时间比较富余,求指点一下https://testerhome.com/topics/8520

vic #4 · 2017年05月05日 Author
王乐新 回复

指点谈不上,互相学习,你确定下你的微信下已打开 TBS 内核 Inspector 调试功能了吗?

vic 回复

是的,不然脚本也运行不了。现在用的坐标元素点击然后用 if else 来判断是否点击到元素上了

vic #16 · 2017年05月05日 Author
王乐新 回复

很无奈,我也爱莫能助了,有解决方式了可以 @ 我一下,学习学习

vic 回复

有另外一种解决方式,不过感觉很 low。我发了一篇帖子,纯新手想求指点一下。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册