Appium 微信 webview 的自动化技术

思寒_seveniruby · 2016年12月30日 · 最后由 白纸 回复于 2021年08月11日 · 20547 次阅读
本帖已被设为精华帖!

最近好多人问微信 webview 自动化的事情, 碰巧我也在追微信 webview 的自动化和性能分析方法.
先发出来一点我的进展给大家参考下. 此方法用于 android 平台, iOS 请自行解决

微信的设置

用微信打开 debugx5.qq.com, 这是个微信的 x5 内核调试页面. 你可以在任何聊天窗口内输入这个网址. 并打开它.
勾选"是否打开 TBS 内核 Inspector 调试功能"

使用 ChromeDriver 编写测试用例

首先安装 ChromeDriver
从官方下载或者从你的 appium 的安装路径里面找 chromedriver. 在 appium 的执行日志里面其实也会打印 chromedriver 的路径的
然后在电脑上启动它, 设置好端口

chromedriver --url-base=wd/hub --port=8000

可以使用 selenium 或者 appium 的客户端去编写测试用例.
如下是我的 scalatest 的测试用例. 大家可以自己用其他的语言实现

test("test chromedriver weixin") {
  val options = new ChromeOptions()
  options.setExperimentalOption("androidPackage", "com.tencent.mm")
  options.setExperimentalOption("androidUseRunningApp", true)
  options.setExperimentalOption("androidActivity", ".plugin.webview.ui.tools.WebViewUI")
  options.setExperimentalOption("androidProcess", "com.tencent.mm:tools")
  val capability = DesiredCapabilities.chrome()
  capability.setCapability(ChromeOptions.CAPABILITY, options)
  val url = "http://127.0.0.1:8000/wd/hub"
  val driver = new AndroidDriver[WebElement](new URL(url), capability)
  driver.get("https://testerhome.com/topics/6954")
  println(driver.getPageSource)
  driver.quit()
}

使用 appium 编写测试用例

有人会经常问为什么 android 上 appium 不能自动化微信 webview, 其实是可以的. 主要是目前的 appium 有个 bug 导致的.
在 appium 中 context 的切换时, 没有带上一个关键的 androidProcess 配置导致的.
他会导致 appium 识别 webview 的时候, 把 com.tencent.mm:tools 的 webview 识别成 com.tencent.mm 的 webview. 从而导致 context 切换失败.

正确的用 appium 测试微信 h5 的方法如下

test("test weixin h5") {
  val capability = new DesiredCapabilities()
  capability.setCapability("app", "")
  capability.setCapability("appPackage", "com.tencent.mm")
  capability.setCapability("appActivity", ".ui.LauncherUI")
  capability.setCapability("deviceName", "emulator-5554")
  capability.setCapability("fastReset", "false")
  capability.setCapability("fullReset", "false")
  capability.setCapability("noReset", "true")
  //capability.setCapability("unicodeKeyboard", "true")
  //capability.setCapability("resetKeyboard", "true")

  //关键是加上这段
  val options = new ChromeOptions()
  options.setExperimentalOption("androidProcess", "com.tencent.mm:tools")
  capability.setCapability(ChromeOptions.CAPABILITY, options)

  val url = "http://127.0.0.1:4723/wd/hub"
  val driver = new AndroidDriver[WebElement](new URL(url), capability)
  println(driver.getPageSource)
  driver.findElementByXPath("//*[@text='我']").click
  driver.findElementByXPath("//*[@text='收藏']").click
  driver.findElementByXPath("//*[contains(@text, '美团外卖')]").click
  println(driver.getPageSource)
  println(driver.getContextHandles)
  driver.context("WEBVIEW_com.tencent.mm:tools")
  println(driver.getPageSource)
}

最关键的就是这句

val options = new ChromeOptions()
options.setExperimentalOption("androidProcess", "com.tencent.mm:tools")
capability.setCapability(ChromeOptions.CAPABILITY, options)

后记

之前测试加上 ChromeOptions 配置的时候没有成功, 我以为是 appium 不支持 ChromeOptions, 就给 appium-android-driver 提交了一个 PR
后来 jlipps 提醒了我一下

我就又追查了几遍, 最后发现是我本地安装 appium 时候加上的 http_proxy 环境变量干扰了 ChromeDriver 的执行.
Appium 其实是支持 ChromeOptions 的

结论也就是现在的 Appium 其实是可以完美的做微信自动化的

我在想我是不是国内第一个提供微信 webview 自动化方法的人 😅
借鉴此思路的同学转发请注明原链. https://testerhome.com/topics/6954

附言 1  ·  2018年04月12日

各位亲,这块的技术问题太多,我没有时间解答。推荐大家学习下 appium 对 webview 的支持和 chromedriver 的原理知识。熟悉这个流程对排查问题很有帮助。

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 151 条回复 时间 点赞
1楼 已删除
陈恒捷 将本帖设为了精华贴 12月30日 22:19

加精理由:简单实用,解决了很多人难以对微信 webview 自动化的问题。

很棒

新年第一个赞给你

意思是还不能用 appium server 去做 android webview 的测试吧?

#7 楼 @wuhao 快了. 我的补丁合并过去就能用 appium 测试了

👍 赞,学习了

棒棒哒,解决大问题。

赞,问一下思寒,结论是 appium 支持 ANDROID 的 webview 自动化吗?目前版本还不支持吧

#11 楼 @oscar webview 一直支持

尝试了这个方法,但是一直提示 org.openqa.selenium.WebDriverException: Not yet implemented

详细日志
org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 37 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'BY-01-0734', ip: '172.20.133.17', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.tencent.mm, networkConnectionEnabled=true, noReset=true, warnings={}, databaseEnabled=false, deviceName=7N2RDQ1484001994, fullReset=false, platform=ANDROID, appActivity=.ui.LauncherUI, desired={appPackage=com.tencent.mm, appActivity=.ui.LauncherUI, noReset=true, newCommandTimeout=600, platformVersion=4.4, fastReset=false, autoWebview=true, chromeOptions={args=[], extensions=[], androidProcess=com.tencent.mm:tools}, platformName=Android, deviceName=Android Emulator, fullReset=false, platform=ANDROID}, newCommandTimeout=600, platformVersion=4.4.2, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, fastReset=false, autoWebview=true, chromeOptions={args=[], extensions=[], androidProcess=com.tencent.mm:tools}, platformName=Android}]
Session ID: 99db07db-1d87-4c45-ba8e-3d63a95d6c94
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:316)
at com.boyaa.test.startAppium(test.java:40)
at com.boyaa.test.main(test.java:77)

已实验,完美支持,下面这段最关键。

// 关键是加上这段
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

@yanzilove ,我和你一样 的问题,解决了吗?

有用 python 的吗,想了半天,还是不知道怎么做

匿名 #17 · 2017年01月09日

你好,driver 切换到 webview 失败,appium 日志如下,请问如何解决

> info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.tencent.mm:tools
> info: [debug] Connecting to chrome-backed webview
> info: Chromedriver: Changed state to 'starting'
> info: Chromedriver: Set chromedriver binary as: D:\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
> info: Chromedriver: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
> info: Chromedriver: No old chromedrivers seemed to exist
> info: Chromedriver: Spawning chromedriver with: D:\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=9515
> info: Chromedriver: [STDOUT] Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 9515
> Only local connections are allowed.
> info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
> info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.14393\"}}}"
> info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"71MBBKU24CU7"}}}
> info: [debug] Didn't get a new command in 60 secs, shutting down...
> info: Shutting down appium session
> info: [debug] Pressing the HOME button
> info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s 71MBBKU24CU7 shell "input keyevent 3"
> info: [debug] Resetting IME to 'com.meizu.flyme.input/com.meizu.input.MzInputService'
> info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s 71MBBKU24CU7 shell "ime set com.meizu.flyme.input/com.meizu.input.MzInputService"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] [UIAUTOMATOR STDOUT] [CDS]close[4724]
> info: [debug] [BOOTSTRAP] [debug] Closed client connection

capability.setCapability("deviceName", "emulator-5554")
模拟器是用的什么创建的呢?

#16 楼 @kgdtkggfqp 我也想知道 请问你解决了嘛

#19 楼 @wuhao 随便写个即可. 如果写错了默认取第一个链接的设备 名字对才选择特定的名字的设备.

#17 楼 @balaroth 是不是你本地有 http_proxy 环境变量什么干扰了

匿名 #23 · 2017年01月10日

@seveniruby 没有哇,无论如何就是切不到 webview,contests 是可以打印出来的,这是代码

#encoding: utf-8
import os
import unittest
import selenium
from appium import webdriver
from time import sleep

PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)

class xcxTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['fastReset'] = 'false'
        desired_caps['fastReset'] = 'false'
        desired_caps['deviceName'] = 'm1_note'
        desired_caps['appPackage'] = 'com.tencent.mm'
        desired_caps['appActivity'] = '.ui.LauncherUI'
        desired_caps['fullReset'] = 'false'
        desired_caps['unicodeKeyboard'] = 'True'
        desired_caps['resetKeyboard'] = 'True'

        options = selenium.webdriver.ChromeOptions()
        options.add_experimental_option('androidProcess', 'com.tencent.mm:tools')

        desired_caps['ChromeOptions.CAPABILITY'] = 'options'

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

    def tearDown(self):
        self.driver.quit()

    def test_didibus(self):
        self.driver.find_element_by_name('发现').click()
        self.driver.find_element_by_name('小程序').click()
        self.driver.find_element_by_name('搜索').click()
        sleep(5)
        self.driver.find_element_by_class_name('android.widget.EditText').send_keys('滴滴公交查询')
        os.popen('adb shell ime set com.meizu.flyme.input/com.meizu.input.MzInputService')
        self.driver.find_element_by_class_name('android.widget.EditText').click()
        os.popen('adb shell input keyevent 66')
        sleep(5)
        print(self.driver.contexts)
        self.driver.switch_to.context(u'WEBVIEW_com.tencent.mm:tools')
        self.driver.find_element_by_class_name('search_item_inner').click()

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(xcxTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

搞了一天了。。。

#23 楼 @balaroth
这句话明显有问题啊. options 是个对象. 被你搞成字符串了. 同样 ChromeOptions.CAPABILITY 也是一样. 这是个变量你必须换成你 python 版本的变量, 他也不是字符串. 这个变量真正的字符串是"ChromeOptions"

desired_caps['ChromeOptions.CAPABILITY'] = 'options'
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

这段用 python 怎么实现 ,搞了一天都没跑通

26楼 已删除
匿名 #27 · 2017年01月10日

@seveniruby 可以了!谢谢

#27 楼 @balaroth 能分享下你的最终代码吗,我也研究这个问题,目前还没进展

@balaroth 分享下你 python 最终代码 为什么我用 谷歌//inspect/#devices 定位 path 一直报错 用法不对吗

@balaroth 还有我贴 options = selenium.webdriver.ChromeOptions() 这段代码的时候 ‘ webdriver’

@dzousigma @weijiatiancai

from appium import webdriver
***********
def setUp(self):

        desired_caps = {
            'platformName': 'Android',
            'fastReset': 'false',
            'deviceName': 'm1_note',
            'appPackage': 'com.tencent.mm',
            'appActivity': '.ui.LauncherUI',
            'fullReset': 'false',
            'unicodeKeyboard': 'True',
            'resetKeyboard': 'True',
            'chromeOptions': {
                'androidProcess' : 'com.tencent.mm:appbrand3'
                }
            }

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

com.tencent.mm:appbrand3 这个根据 webview 的 context 改
这是 setUp 方法的写法,已经可以切到微信的 webview 了,不过有一些 webview 控件定位的细节还是不太懂,谁弄明白搞一份示例代码贴出来谢谢了

@balaroth 你代码前面都没什么问题 就是最后 搜索出来的 ‘滴滴公交搜索 ‘ 这时候已经切换到 webview 界面了 然后执行点击

self.driver.find_element_by_class_name('search_item_inner').click() 执行失败报错
然后我用
self.driver.find_element_by_xpath('//*[@id="search_result"]/div[3]/div[1]/div/ul/li/div').click() 也报错了

有大神知道问题的说下 用的是谷歌的 inspect 定位 报错代码如下:
Error
Traceback (most recent call last):

File "/Users/daodaoge/PycharmProjects/untitled2/test.py", line 160, in test_scroll
self.driver.find_element_by_xpath('//*[@id="search_result"]/div[3]/div[1]/div/ul/li/div').click()
File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 293, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 752, in find_element
'value': value})['value']
File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "build/bdist.macosx-10.6-intel/egg/appium/webdriver/errorhandler.py", line 29, in check_response
raise wde
NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

@weijiatiancai ,我的成功运行,调试过程中也出现过你这个错误。从报错来看,应该是没有切换到 webview,检查 chromeOptions 配置,和 switch_to.context 方法有没有问题 。

@hukui51770 chromeOptions 已经打开 TBS 内核 Inspector 调试

print(self.driver.contexts) :内容如下
[u'NATIVE_APP', u'WEBVIEW_com.tencent.mm:tools']
我感觉应该是进入了 print 结果如下:
NATIVE_APP
未找到
WEBVIEW_undefined
未找到
success
我 Setup:
'chromeOptions': {
'androidProcess' : 'com.tencent.mm:appbrand1'
}
我一直不理解 appbrand1 代表什么意思 可以是 appbrand2?appbrand3?吗
执行操作进入 webview 界面 代码:
self.driver.switch_to.context(u'WEBVIEW_com.tencent.mm:tools')

不知道到底哪里错误 用的是谷歌的 inspect 定位
求大神指点...

@hukui51770 能贴个你成功完整的代码不 谢谢了 搞了二天没成功 ☹️😞

@weijiatiancai ,driver.contexts print 出来的是 WEBVIEW_com.tencent.mm:tools,所以配置'chromeOptions': {
'androidProcess' : 'com.tencent.mm:tools',切换进入也是 switch_to.context('WEBVIEW_com.tencent.mm:tools')。

@hukui51770 @balaroth 我想问一下你们 楼主说的那个 chromedriver 你们启动了么 需要添加环境变量吗 , 具体的操作能说说么 不是太懂这个插件 还有楼主说的端口 设置成 8000...有影响吗

@xiaoxuxu 。没有添加 chromedriver 环境变量和启动它,appium 会自己启动它。微信要打开 Inspector 调试,下面是我的全部代码

from appium import webdriver
import time

desired_caps = {'platformName': 'Android',
'platformVersion': '5.1.1',
'deviceName': '8692_A00',
'app': '',
'appPackage': 'com.tencent.mm',
'appActivity':'.ui.LauncherUI',
'unicodeKeyboard': True,
'resetKeyboard': True,
'chromeOptions': {'androidProcess': 'com.tencent.mm:tools'}
}

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

driver.find_element_by_id('com.tencent.mm:id/bm6').click()
driver.find_element_by_id('com.tencent.mm:id/adq').click()
driver.find_element_by_name('佣金提现').click()
time.sleep(3)
print(driver.contexts)
driver.switch_to.context('WEBVIEW_com.tencent.mm:tools') # 切换进入 webview
driver.find_element_by_xpath('/html/body/section/section/div/div[3]/ul/li[1]/a').click()
driver.quit()

@hukui51770 真心非常感激 你 webview 定位的元素用的什么工具? 我用的 appium 版本 1.4

@xiaoxuxu 微信上切换到 webview 页面,在 google 浏览器中输入 chrome://inspect/#devices,会看到自己的 webview 页面地址,点击 inspect 就在网页打开了,然后就和 web 定位控件一样,找到你想要的控件,右键 copy xpath 就 ok 了。也可以自己把那个链接复制,在浏览器打开然后点击 google 开发者工具,和前面一样操作

@hukui51770 非常感谢 很详细 !!

@seveniruby @hukui51770 @balaroth 请问下 我 print(self.driver.contexts) 如:
[u'NATIVE_APP', u'WEBVIEW_com.tencent.mm:tools', u'WEBVIEW_com.android.quicksearchbox']
然后我 self.driver.switch_to.context('WEBVIEW_com.android.quicksearchbox')
执行程序的时候一直处于缓冲状态 没报错也没执行 等了 10 分钟还是老样子 请问这是什么情况
'chromeOptions': {
'androidProcess' : 'WEBVIEW_com.android.quicksearchbox'
求指教


已经找到 web view 了 然后 self.driver.switch_to.context('WEBVIEW_com.tencent.mm:tools') 一直处于缓冲状态!!有大神知道原因么

我是在 mac 上 chromedriver 已放在 appium 的路径下

贴下报错代码
self.driver.find_element_by_class_name("gj-home-lock-tip").click()
self.error_handler.check_response(response)
File "build/bdist.macosx-10.6-intel/egg/appium/webdriver/errorhandler.py", line 29, in check_response
raise wde
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"class name","selector":"gj-home-lock-tip"}
(Session info: webview=37.0.0.0)
(Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.5 x86_64)

进行转换 webview 界面的时候 等了大概 1 分钟左右 然后 print 提示成功了...之后执行界面元素定位 就报错

@seveniruby 你说 appium 时候加上的 http_proxy 环境变量干扰了 ChromeDriver 的执行 需要怎么解决这个问题?

47楼 已删除

#46 楼 @Tester957 去掉不就行了. unset 下. 你这是要别人手把手的教啊...回复的内容干扰版面, 我先删除了

@sevenlruby 请问楼主 我 appium 提示 chrome not reachable 是什么情况?

#31 楼 @balaroth 有个问题想请教,搜索出来 ‘滴滴公交搜索 ‘ 的结果后,控件定位也没报错,但怎么点击控件以后没有跳转页面...你那边是否有这种情况?
为了验证是否有执行点击操作,我特意写了几个点击操作,都顺利执行了,就是点击后无反应
self.driver.switch_to.context(u'WEBVIEW_com.tencent.mm:tools')
self.driver.find_element_by_xpath('//[@id="search_result"]/div[3]/div[1]/div/ul/li[1]').click()
print "1"
self.driver.find_element_by_xpath('//
[@id="search_result"]/div[3]/div[1]/div/ul/li/div/div[2]/div/p[1]').click()
print "2"
self.driver.find_element_by_xpath('//*[@id="search_result"]/div[3]/div[1]/div/ul/li/div/div[2]/div').click()
print "3"
另外发现在谷歌开发者工具的 inspect 页面能拉动该结果页面,但点击也是没有跳转动作的😂 😂 只有我遇到这种情况吗?

我的报错代码 :
Chromedriver: Error: An error occurred (Original error: chrome not reachable
(Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.5 x86_64))
at JWProxy.command$ (lib/proxy.js:149:15)
at tryCatch (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-chromedriver/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-chromedriver/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at bound (domain.js:254:14)
at GeneratorFunctionPrototype.runBound (domain.js:267:12)
at run (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-chromedriver/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:89:39)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-chromedriver/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js💯28
at process._tickDomainCallback (node.js:381:11)
{ [Error: An error occurred (Original error: chrome not reachable
(Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.5 x86_64))]
status: 100,
value: { message: 'chrome not reachable\n (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.5 x86_64)' },
httpCode: 200 }

info: --> GET /wd/hub/status {}

error: Could not proxy command to remote server. Original error: connect ECONNREFUSED

info: JSONWP Proxy: Proxying [GET /wd/hub/status] to [GET http://127.0.0.1:9515/wd/hub/status] with body: {}

info: --> GET /wd/hub/status {}

error: Could not proxy command to remote server. Original error: connect ECONNREFUSED

info: JSONWP Proxy: Proxying [GET /wd/hub/status] to [GET http://127.0.0.1:9515/wd/hub/status] with body: {}

info: --> GET /wd/hub/status {}

error: Could not proxy command to remote server. Original error: connect ECONNREFUSED

info: JSONWP Proxy: Proxying [GET /wd/hub/status] to [GET http://127.0.0.1:9515/wd/hub/status] with body: {}

info: --> GET /wd/hub/status {}

error: Could not proxy command to remote server. Original error: connect ECONNREFUSED

info: JSONWP Proxy: Proxying [GET /wd/hub/status] to [GET http://127.0.0.1:9515/wd/hub/status] with body: {}

info: --> GET /wd/hub/status {}

error: Chromedriver: Chromedriver exited unexpectedly with code null, signal SIGTERM

info: Chromedriver: Changed state to 'stopped'

error: Chromedriver: Error: An error occurred (Original error: chrome not reachable
(Driver info: chromedriver=2.18.343837

warn: Chromedriver for context WEBVIEW_com.tencent.mm:tools stopped unexpectedly
warn: Chromedriver quit unexpectedly, but it wasn't the active context, ignoring


我的不知道为什么 context 只有 native_app

#38 楼 @hukui51770 您好 想问一下 您是怎么获取到 context 的 我也有打印 但是没有这个呢

一直提示这玩意

WebDriverException: Message: unknown error: Chrome version must be >= 54.0.2840.0

看了下手机的 chrome 都 55 了

我也遇到一样的问题@codeskyblue,提示:unknown error: Chrome version must be >= 54.0.2840.0\n (Driver info: chromedriver=2.27.440174 。不知道怎么处理。

#58 楼 @happymff 猜测是微信的 WebKit 版本不够导致的,或许应该把 chromedriver 或者 selenium 的版本降低一点

#59 楼 @codeskyblue 您好,我的微信的 Webview 显示的是 53.0.2785.49,然后我手机上的 Chrome 是 55 的,这个有影响么?chromedriver 具体是根据哪个版本来选择合适的?是根据微信 Webview 的么?

#60 楼 @happymff 应该是微信的 WebView,你降低 chromedriver 版本,试验的效果怎么样?另外微信 WebView 的版本号你是在哪里看到的?

#61 楼 @codeskyblue chromedriver 我降到了 2.3,2.4,2.5,2.2,2.1,目前提示的错误信息不一样了,代码运行到切换 webview 之后,一直没有响应,最后提示 org.openqa.selenium.NoSuchSessionException: no such session。server 端的提示信息是:我上传一个截图吧。

微信的 WebView 版本可以通过 Chrome 的 ADB plugins 在 Inspect 页面元素的时候看到。

@codeskyblue 你那边的微信小程序,测试是可以通过的么?谢谢~

#64 楼 @codeskyblue 我觉得我这边现在是切换到了 WebView,但是不能对其元素进行操作,不知道具体问题在哪了,也可能是权限问题,H5 开发的时候,不让对其元素进行操作,这是我的猜测。你那边要是解决了,到时候分享一下哈~

#65 楼 @happymff 我也只是为了测试 ATX 对 WEBVIEW 支持的情况如何才弄的,应该不会怎么关注。

@codeskyblue 谢谢,我的问题解决了,最终用的 chromedriver2.5,解决了问题,配置代码如下:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platform", "ANDROID");
caps.setCapability("platformVersion", "5.1.1");
caps.setCapability("deviceName", "A02AECPB2CLTG");
caps.setCapability("browserName", "");
caps.setCapability("app", "");

caps.setCapability("appPackage", "com.tencent.mm");
caps.setCapability("appActivity", ".ui.LauncherUI");
caps.setCapability("fastReset", "false");
caps.setCapability("fullReset", "false");
caps.setCapability("noReset", "true");

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("androidProcess", "com.tencent.mm:appbrand1");
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
实现代码如下:
@Test
public void miniProgramTest() throws Exception {

// println(driver.getPageSource)
driver.findElementByXPath("//[@text='发现']").click();
Thread.sleep(1000);
driver.findElementByXPath("//
[@text='小程序']").click();
Thread.sleep(1000);
driver.findElementByXPath("//[contains(@text, 'QQ 阅读')]").click();
Thread.sleep(3000);
driver.findElementByXPath("//
[@text='书库']").click();
Set contextNames = driver.getContextHandles();
Thread.sleep(1000);
for (String contextName : contextNames) {
System.out.println(contextName);
}
driver.context("WEBVIEW_com.tencent.mm:tools");
Thread.sleep(1000);
System.out.println("已经进入 WEBVIEW 啦");
//System.out.println(driver.getPageSource());
String s1 = driver.getWindowHandle();

driver.findElementByXPath("//*[contains(@url, '古代')]").click();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
Set set1 = driver.getWindowHandles();
//System.out.println(set1);
for(String windows: set1){
if (windows.equalsIgnoreCase(s1)){

}else{
driver.switchTo().window(windows);
}
}
//driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
Thread.sleep(2000);
driver.findElementByXPath("//[contains(@url, 'bid=716295')]").click();
String s2 = driver.findElementByXPath("//
[contains(@url, 'bid=716295')]").getText();
System.out.println(s2);
Assert.assertTrue(s2.contains("美人榻"));
Thread.sleep(3000);
driver.context("NATIVE_APP");
System.out.println("已经回到 NativeAPP 啦");
driver.findElementById("com.tencent.mm:id/io").click();
//driver.findElement(By.id("com.tencent.mm:id/io")).click();
}
代码运行正常了,有遇到同样的问题,可以尝试一下我的方法。

@zrleo 我也遇到你这个情况,只有一个 context,请问你后来怎么解决的?

谢谢楼主,很赞!
其实楼主的意思就是现在 Appium 切换 context 到 webview 的时候有 bug,所以新建 Appium 实例的时候需要加个参数,Ruby 的代码没这么复杂

caps = 
  { "platformName" => "Android",
    "platformVersion" => "5.1",
    "deviceName" => "",
    "appPkg" => "com.tencent.mm",
    "appWaitPackage" => "com.tencent.mm",
    "appActivity" => ".ui.LauncherUI",
    "appWaitActivity" => ".ui.LauncherUI",
    "noReset" => true,
    "chromeOptions" => { "androidProcess" => "com.tencent.mm:tools" } }
Appium::Driver.new(caps: caps).start_driver

大家有没有遇到,在 webview 操作,点击跳转到另一个页面后就不能进行点击、输入等操作了

File "C:/Users/Administrator/Desktop/h5.py", line 58, in test_h5
self.dr.find_element_by_class_name("weui_navbar_item").click()
AttributeError: 'NoneType' object has no attribute 'click'

#72 楼 @D6666666 有的!在 webview 里进另一个页面再去find_element的话,服务端会报ESOCKETTIMEDOUT的错误。

[MJSONWP] Encountered internal error running command: Error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: Error: ESOCKETTIMEDOUT
    at doJwpProxy$ (../../../lib/mjsonwp/mjsonwp.js:343:13)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)

#73 楼 @chaoli46 是的,你解决了吗?

#74 楼 @D6666666 没有呢,刚去 github 提了个 bug ( https://github.com/appium/appium/issues/7863 ),不过看起来像是微信的 bug。

76楼 已删除
77楼 已删除
79楼 已删除

@all,谁知道 .net 应该怎么写,下面这样写切换不成功:

AndroidDriver<IWebElement> driver = null;
IWebElement element = null;
DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.SetCapability("app", "");
capabilities.SetCapability("deviceName", "android emulator");
capabilities.SetCapability("browserName", "");
capabilities.SetCapability("platformName", "android");
capabilities.SetCapability("platformVersion", "7.0");//手机操作系统版本
capabilities.SetCapability("newCommandTimeout", "300"); ////设置命令超时时间,单位:秒。达到超时时间仍未接收到新的命令时 Appium 会假设客户端退出然后自动结束会话。
capabilities.SetCapability("unicodeKeyboard", "True");//使用 Unicode 输入法。默认值 false
capabilities.SetCapability("resetKeyboard", "True"); //在设定了 unicodeKeyboard 关键字的 Unicode 测试结束后,重置输入法到原有状态。如果单独使用,将会被忽略。默认值 false
capabilities.SetCapability("appPackage", "com.tencent.mm");
capabilities.SetCapability("appActivity", ".ui.LauncherUI");
capabilities.SetCapability("automationName", "appium");
capabilities.SetCapability("fastReset", "false");
capabilities.SetCapability("fullReset", "false");
capabilities.SetCapability("noReset", "true");

ChromeOptions options  = new ChromeOptions();
options.AddAdditionalCapability("androidProcess", "com.tencent.mm:tools");
capabilities.SetCapability(ChromeOptions.Capability, options);


Uri serverUri = new Uri("http://127.0.0.1:4723/wd/hub");
try
{
    //System.IO.File.AppendAllText("D:\\PageSources.xml",driver.PageSource);
    driver = new AndroidDriver<IWebElement>(serverUri, capabilities, TimeSpan.FromSeconds(180));
    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
    driver.FindElementByXPath("//*[@text='通讯录']").Click();
    driver.FindElementByXPath("//*[@text='公众号']").Click();
    driver.FindElementByAccessibilityId("搜索").Click();
    driver.FindElementByXPath("//*[@text='搜索']").SendKeys("美");
    driver.FindElementByXPath("//*[@text='美团']").Click(); 
    driver.FindElementByXPath("//*[@text='吃喝玩乐']").Click();
    driver.FindElementByXPath("//*[contains(@text,'附近优惠')]").Click();
    Console.WriteLine(driver.Contexts);
    Console.WriteLine(driver.PageSource);

    var contexts = ((IContextAware)driver).Contexts;
    string webviewContext = null;
    for (int i = 0; i < contexts.Count; i++)
    {
        Console.WriteLine(contexts[i]);
        if (contexts[i].Contains("WEBVIEW"))
        {
            webviewContext = contexts[i];
            break;
        }
    }
    Assert.IsNotNull(webviewContext);
    ((IContextAware)driver).Context = webviewContext;

    Thread.Sleep(3000);
    driver.Quit();
}
catch (Exception)
{
    if (driver != null)
    {
        driver.Quit();
    }
}

报错信息:

[2017-03-22 12:15:38][AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:tools'
[2017-03-22 12:15:38][AndroidDriver] A port was not given, using random port: 8000
[2017-03-22 12:15:38][Chromedriver] Changed state to 'starting'
[2017-03-22 12:15:38][Chromedriver] Set chromedriver binary as: C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
[2017-03-22 12:15:38][Chromedriver] Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"8000 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %a))
[2017-03-22 12:15:38][Chromedriver] No old chromedrivers seemed to exist
[2017-03-22 12:15:38][Chromedriver] Spawning chromedriver with: C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=8000 --adb-port=5037
[2017-03-22 12:15:38][Chromedriver] [STDOUT] Starting ChromeDriver 2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30) on port 8000
Only local connections are allowed.
[2017-03-22 12:15:38][JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[2017-03-22 12:15:38][JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.10240\"}}}"
[2017-03-22 12:15:38][JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"BinaryLocation":null,"LeaveBrowserRunning":false,"Proxy":null,"Arguments":[],"Extensions":[],"DebuggerAddress":null,"MinidumpPath":null,"PerformanceLoggingPreferences":null,"androidDeviceSerial":"APU7N16309003842"}}}
[2017-03-22 12:15:38][JSONWP Proxy] Got response with status 200: {"sessionId":"1cf680ec27eb7ed6a73be8c1e88c798c","status":13,"value":{"message":"unknown error: cannot parse capability: chromeOptions\nfrom unknown error: unrecognized chrome option: Arguments\n (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64)"}}
[2017-03-22 12:15:38][JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"BinaryLocation":null,"LeaveBrowserRunning":false,"Proxy":null,"Arguments":[],"Extensions":[],"DebuggerAddress":null,"MinidumpPath":null,"PerformanceLoggingPreferences":null,"androidDeviceSerial":"APU7N16309003842"}}}
[2017-03-22 12:15:38][JSONWP Proxy] Got response with status 200: {"sessionId":"157d64dd57fef1ceb42aca0f3c6282dd","status":13,"value":{"message":"unknown error: cannot parse capability: chromeOptions\nfrom unknown error: unrecognized chrome option: Arguments\n (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64)"}}
[2017-03-22 12:15:38][JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"BinaryLocation":null,"LeaveBrowserRunning":false,"Proxy":null,"Arguments":[],"Extensions":[],"DebuggerAddress":null,"MinidumpPath":null,"PerformanceLoggingPreferences":null,"androidDeviceSerial":"APU7N16309003842"}}}
[2017-03-22 12:15:38][JSONWP Proxy] Got response with status 200: {"sessionId":"f2b4c509ad0b66b50e6204cda6949705","status":13,"value":{"message":"unknown error: cannot parse capability: chromeOptions\nfrom unknown error: unrecognized chrome option: Arguments\n (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64)"}}
[2017-03-22 12:15:38][JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"BinaryLocation":null,"LeaveBrowserRunning":false,"Proxy":null,"Arguments":[],"Extensions":[],"DebuggerAddress":null,"MinidumpPath":null,"PerformanceLoggingPreferences":null,"androidDeviceSerial":"APU7N16309003842"}}}
[2017-03-22 12:15:38][JSONWP Proxy] Got response with status 200: {"sessionId":"2bebd54f4a175642d051bbafee2d7a5f","status":13,"value":{"message":"unknown error: cannot parse capability: chromeOptions\nfrom unknown error: unrecognized chrome option: Arguments\n (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64)"}}
[2017-03-22 12:15:38][Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[2017-03-22 12:15:38][Chromedriver] Changed state to 'stopped'
[2017-03-22 12:15:38][Chromedriver] Error: unknown error: cannot parse capability: chromeOptions
from unknown error: unrecognized chrome option: Arguments
(Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\lib\chromedriver.js:176:15)
at tryCatch (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\node_modules\babel-runtime\regenerator\runtime.js:136:37)
Error: unknown error: cannot parse capability: chromeOptions
from unknown error: unrecognized chrome option: Arguments
(Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\lib\chromedriver.js:176:15)
at tryCatch (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[2017-03-22 12:15:38][MJSONWP] Encountered internal error running command: Error: unknown error: cannot parse capability: chromeOptions
from unknown error: unrecognized chrome option: Arguments
(Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\lib\chromedriver.js:176:15)
at tryCatch (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\stephen\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium-chromedriver\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[2017-03-22 12:15:38][HTTP] <-- POST /wd/hub/session/1f06a81d-0a2e-4840-a4da-b800c9c7e26e/context 500 1441 ms - 407

Stepthen [该话题已被删除] 中提及了此贴 03月22日 15:26
Stepthen 回复
  • 已解决 -

将下代码


ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("androidProcess", "com.tencent.mm:tools");
capabilities.SetCapability(ChromeOptions.Capability, options);

替换为:

DesiredCapabilities option = new DesiredCapabilities();
option.SetCapability("androidProcess", "com.tencent.mm:tools");
capabilities.SetCapability(ChromeOptions.Capability, option.ToDictionary());

请问楼主有没有 在 native_app 与 webview 之间进行多次切换测试?我只发现第一次从 native_app 切到 webview 是成功的,从 webview 切回 native_app ,再切到 webview 就失败了。@seveniruby

yukikla 回复

同问,我也遇到了同样的问题,不知道楼主解决没?

Li Chao 回复

开始有点问题,后来发现是没切换 context,我也是用 ruby,多交流。


为什么这两句话执行了以后不报错,但是点击事件也没生效呢?
driver.find_element_by_xpath('//[@id="combo"]/li[1]/div[1]').click()
driver.find_element_by_xpath('//
[@id="combo"]/li[1]/div[2]').click()
xpath 是用谷歌调试那个找的,应该没问题

yukikla 回复

我也卡在这里了,请问你的问题解决了吗

王乐新 回复

之前也遇到了相同问题,换了一些其他公众号的 webview 试了一下,有些是可以的(比如填写表单),有些就不行(比如点击项目跳转),结论是的确切换到了 webview 并且找到了该元素(用 getText 方法能得到 text),不然会报 unable to find xxxxx,猜想是不是当前 webview 本身有什么限制

evon4555 回复

我卡在这里一个星期了,我用 xpath 可以定位到,但是就是 click 事件不生效。而且现在业务就在微信一块,如果不能跑通那自动化根本就搞不起来😂

evon4555 回复

https://testerhome.com/topics/3591
刚刚看了下这篇帖子,好像有点思路了。我去试试看

王乐新 回复

成功了求指点啊

我刚把我要测的页面在电脑上用 chrome 打开,发现电脑上也不能用常规的操作进行点击,你试试看你的页面
如果是这样的话,我还是觉得微信平台上限制了什么。。。我得找开发问问去

所以如果电脑上搞定了,可以点击,app 上一定可以用相同的方法处理 H5

evon4555 回复

我这边查资料总算查出来了一点头绪,

我可以用这两句话来对 webview 页面进行操作了,头疼的就是这个定位问题不好解决,但是总算是可以对页面进行操作了
方法可以参考这个网址http://www.exceptionhelp.com/autotestdetail?articleId=82
这个是扩展用法:http://www.exceptionhelp.com/autotestdetail?articleId=69

坑,fastReset 和 fullReset 千万不要写!!刚刚血一样的教训,我微信的数据全被清空了!!!!!!!!!!!!!!!!!!!!!!!!

想请问一下,就是切换之后一直在等待状态是什么原因呢?

然后有时能成功进行转换后的操作,有时候又不行。

[36minfo[39m: Chromedriver: Changed state to 'starting'
[36minfo[39m: Chromedriver: Set chromedriver binary as: C:\Program Files\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
[36minfo[39m: Chromedriver: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
[36minfo[39m: Chromedriver: No old chromedrivers seemed to exist
[36minfo[39m: Chromedriver: Spawning chromedriver with: C:\Program Files\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=9515
[36minfo[39m: Chromedriver: [STDOUT] Starting ChromeDriver 2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a) on port 9515
Only local connections are allowed.
[36minfo[39m: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
[36minfo[39m: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"6.1 SP1\"}}}"
[36minfo[39m: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"extensions":[],"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"DBH9X...
[36minfo[39m: Shutting down appium session
[36minfo[39m: JSONWP Proxy: Got response with status 200: {"sessionId":"9a59fc16f0e2597ef205cad6275ca31c","status":100,"value":{"message":"chrome not reachable\n  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=W...
[36minfo[39m: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"extensions":[],"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"DBH9X...
[36minfo[39m: JSONWP Proxy: Got response with status 200: {"sessionId":"9034159efd8e429fca558c83cb652a75","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSel...
[36minfo[39m: Chromedriver: Changed state to 'online'

大家有遇到这个错误么,求帮忙解决一下:WebDriverException: An unknown server-side error occurred while processing the command. Original error: session not created exception: please close 'com.tencent.mm' and try again
我的代码:driver.context("WEBVIEW_com.tencent.mm:tools")(使用这个 driver)

我的 chromeDriver 版本:

异常信息:

Appium 出错信息:

baxia 回复

已经找到出错的原因了。是因为我测试的 app 不是微信(只是测试我的 apk 跳转到微信的 webview 页面点击操作),可能是当前测试应用和配置的 webview 的那个 driver 不相匹配而失败的。如果这不是根本原因还请大家指正

匿名 #100 · 2017年05月24日

切换回 NATIVE_APP,杀掉 chromedriver,再进入 webview

我也碰到了类似问题。杀 chromedriver 进程有点儿郁闷。各位大神还有别的好办法么? @Lihuazhang @seveniruby

@skytraveler 用 appium1.5 版本 设置 desired_caps['recreateChromeDriverSessions'] = True 切换到非 chrome-Driver 会 kill 掉 session,就不需要手动 kill 了。

沙子 回复

问题解决了。可以来回切换了。感谢!

感谢黄老师和各位提供细节的同学,全搞定了。作为 appium 的新手菜鸟回馈一下几个细节:

1.chromedriver 可以在起 appium 的时候当启动参数参数,这样就不用单起了 appium --no-reset --chromedriver-port 8000
2.capabilities.setCapability("recreateChromeDriverSessions", "True"); 这句很重要,否则 webview 和 native 来回切会有问题。
3.在微信里打开调试选项后,可以用 chrome 的内建插件 inspect H5 的文档结构。

贴下比较 low 的代码,代码实现了根据给定列表遍历给定公众号历史文章的 demo 功能,期间数次 native 和 webview 的切换:

import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.URL;
import java.util.ArrayList;

import org.junit.*;

/**
 * Created by lucas on 2017/5/31.
 */
public class AndroidTest {

    private static final int NUMBER_ALLOWED = 3;

    @Test
    public void invokeSnowball() throws Exception {


        AndroidDriver driver = this.GetAndroidDriver();

        //进入公众号列表
        this.GotoList(driver);

        //遍历列表
        for (String name : this.GetSearchList()) {
            if (this.GotoMessageHistory(driver, name)) {
                //遍历列表给出的文章
                this.getArticleDetail(driver, name);
            }
            //返回公众号列表
            this.GoBackToList(driver);
        }
    }

    //进入公众号列表的操作
    private void GotoList(AndroidDriver driver) throws Exception {
        Thread.sleep(5000);
        driver.findElement(By.xpath("//android.widget.TextView[@text='通讯录']")).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("//android.widget.TextView[@text='公众号']")).click();
    }

    //定义搜索列表
    private ArrayList<String> GetSearchList() {
        return new ArrayList<String>() {{
            add("漫画项目管理");
            add("阿尔法工场");
            add("阿里研究院");
            add("安卓开发精选");
        }};
    }

    private void getArticleDetail(AndroidDriver driver, String name) throws Exception {

        for (int i = 1; i <= NUMBER_ALLOWED; i++) {
            driver.context("WEBVIEW_com.tencent.mm:tools");
            System.out.println("切换到WEBVIEW上下文");
            if (isElementExist(driver, By.xpath("//*[@id='js_msg_card']"))) {
                System.out.println("获取到了公众号文章列表");

                //点击文章
                if (isElementExist(driver, By.xpath("//*[@class='weui_msg_card_bd']/div[" + i + "]"))) {
                    driver.findElement(By.xpath("//*[@class='weui_msg_card_bd']/div[" + i + "]")).click();
                    Thread.sleep(2000);
                    System.out.println("公众号:" + name + "第" + i + "篇文章被点击");

                    //切换回native的context
                    driver.context("NATIVE_APP");
                    System.out.println("NATIVE_APP");
                    if (isElementExist(driver, By.id("h4"))) {
                        driver.findElement(By.id("h4")).click(); //返回对应公众号的文章列表.
                        System.out.println("关闭公众号文章,回到H5列表");
                    } else {
                        System.out.println("未能正常回退,请关注");
                    }

                }

            } else {
                System.out.println("公众号没有历史文章");
            }

        }
        //最后回到公众号列表,需要后退,切回native方式.
        driver.context("NATIVE_APP");
        System.out.println("NATIVE_APP");


    }


    //搜索一个公众号,并进入历史文章列表
    private boolean GotoMessageHistory(AndroidDriver driver, String name) throws Exception {

        Thread.sleep(2000);
        driver.findElement(By.xpath("//android.widget.TextView[@content-desc='搜索']")).click();
        Thread.sleep(2000);
        WebElement inputGZ = driver.findElement(By.xpath("//android.widget.EditText[@text='搜索']"));
        inputGZ.click();
        inputGZ.sendKeys(name);
        Thread.sleep(2000);

        //搜到了的处理方式
        if (isElementExist(driver, By.xpath("//android.widget.TextView[@text='" + name + "']"))) {
            driver.findElement(By.xpath("//android.widget.TextView[@text='" + name + "']")).click();
            Thread.sleep(2000);
            Thread.sleep(2000);
            driver.findElement(By.xpath("//android.widget.TextView[@content-desc='聊天信息']")).click();
            Thread.sleep(2000);
            driver.findElement(By.xpath("//android.widget.TextView[@text='查看历史消息']")).click();
            Thread.sleep(5000);  //页面加载时间太长
            return true;
        } else {
            System.out.println("未能找到公众号:"+name);
            return false;
        }

    }

    private AndroidDriver GetAndroidDriver() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformVersion", "7.0");
        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage", "com.tencent.mm");
        capabilities.setCapability("appActivity", ".ui.LauncherUI");
        capabilities.setCapability("unicodeKeyboard", "True");
        capabilities.setCapability("resetKeyboard", "True");
        capabilities.setCapability("recreateChromeDriverSessions", "True");

        //加入微信webwiew调试能力.
        ChromeOptions options2 = new ChromeOptions();
        options2.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
        capabilities.setCapability(ChromeOptions.CAPABILITY, options2);
        return new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }


    //回到list
    private void GoBackToList(AndroidDriver driver) throws Exception {


        while (isElementExist(driver, By.id("h4"))) {
            driver.findElement(By.id("h4")).click(); //碰上h4就不停返回
            Thread.sleep(2000);
        }

        if (isElementExist(driver, By.id("go"))) {
            driver.findElement(By.id("go")).click(); //再多试一遍
            Thread.sleep(2000);
        }

        if (isElementExist(driver, By.id("gw"))) {
            driver.findElement(By.id("gw")).click(); //再多试一遍
            Thread.sleep(2000);
        }
        System.out.println("已经回到搜索列表");

    }


    private boolean isElementExist(AndroidDriver driver, By locator) {
        try {
            driver.findElement(locator);
            return true;
        } catch (NoSuchElementException ex) {
            return false;
        }
    }


}
刘晓光 回复

代码封装的不错,但是一个疑问和一个问题
1、capabilities.setCapability("deviceName", "Android Emulator"); 在模拟器中运行,实际微信在模拟器中运行不了的吧
2、进入 “查看历史消息” 查看 context ,只有一个 NATIVE_APP 没有看到有 WEBVIEW_com.tencent.mm:tools,所以没有办法切换过去。是我用的微信版本不对?

ding 回复

是的,有个 WEBVIEW_com.tencent.mm:tools 识别错误的 bug,思寒有一篇这个说明的帖子,你去查看吧

我这边遇到的情况是:前几天试验都是有 web view 的,突然从今天下午开始,即使在 h5 页面,也看不到 web view,用 uiautomatorview 查看 h5 页面,居然能识别 h5 页面的元素,感觉 h5 页面变成了原生 android 元素了,这样一来,反而不用切换到 webview 就能直接操作了,这个转变蛮好的,但是不知道什么决定了这个转变?由谁知道?

请教各位大侠,我测微信小程序的时候,切换 webview 报错

基本设置:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("androidProcess", "com.tencent.mm:appbrand0");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

当代码执行到这里就报错了:
driver.context("WEBVIEW_com.tencent.mm:tools");

控制台日志:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: session not created exception: please close '' and try again
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4.98 seconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'YK-DZ-4711702', ip: '172.168.16.110', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.tencent.mm, noReset=true, deviceName=05157df5a207d11f, fullReset=false, platform=LINUX, deviceUDID=05157df5a207d11f, desired={appPackage=com.tencent.mm, noReset=true, deviceName=05157df5a207d11f, fullReset=false, appActivity=.ui.LauncherUI, platformVersion=6.0.1, browserName=, fastReset=false, unicodeKeyboard=true, chromeOptions={args=[], extensions=[], androidProcess=com.tencent.mm:appbrand0}, udid=05157df5a207d11f, platformName=Android, resetKeyboard=true}, platformVersion=6.0.1, webStorageEnabled=false, takesScreenshot=true, browserName=, javascriptEnabled=true, unicodeKeyboard=true, udid=05157df5a207d11f, platformName=Android, deviceManufacturer=samsung, resetKeyboard=true, deviceScreenSize=1440x2560, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, appActivity=.ui.LauncherUI, locationContextEnabled=false, deviceModel=SM-G9208, fastReset=false, chromeOptions={args=[], extensions=[], androidProcess=com.tencent.mm:appbrand0}}]
Session ID: a9c2ce80-0091-43d1-8c71-73ac8e955e02

appium 日志:
[Chromedriver] Error: session not created exception: please close '' and try aga
in
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9
cf),platform=Windows NT 6.1.7601 SP1 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:176:15)
at tryCatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\
node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\Administrator\AppData\Roaming
\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:3
7)
Error: session not created exception: please close '' and try again
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9
cf),platform=Windows NT 6.1.7601 SP1 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:176:15)
at tryCatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\
node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\Administrator\AppData\Roaming
\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:3
7)
[MJSONWP] Encountered internal error running command: Error: session not created
exception: please close '' and try again
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9
cf),platform=Windows NT 6.1.7601 SP1 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:176:15)
at tryCatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\
node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\Administrator\AppData\Roaming
\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:3
7)
[HTTP] <-- POST /wd/hub/session/a9c2ce80-0091-43d1-8c71-73ac8e955e02/context 500
4980 ms - 357

请问是怎么回事呢?

Stepthen 回复

好像 Contexts 集合里面只有一个 Native 返回,并没有对应的 WebView_com.tencent.mm:tools。同样还是得不到 WebView 里面的内容。

知行合一 回复

可以试下这样行不行:如果只有一个 native,就可以停止运行脚本,保持 H5 页面一直处于显示状态,用 uiautomatorviewer.bat 查看,可以定位到页面元素,这样就不用切换 context,就可以直接 findelementbyxpath("xxxx")操作了。

ding 回复

1.插上真机就变成真机了,我是 appium 小白,机理不知道,猜测有个优先调用顺序。我微信在 genymode 里安装失败了,别的没试过。
2.只有微信历史列表是 h5 写的,并且需要操作它的元素,所以才切换,每次循环都切回来。我那个版本的代码有瑕疵,现在为了搞定各种异常,代码量已经翻了三四倍了,凑合着当例子看吧。
3.微信装在不同 android 机的同一个按钮竟然叫法不同。也是醉了。所以就算是要得到一个返回按钮的 id,要这么写:

public String PickID(AndroidDriver driver){

if(isElementExist(driver, By.id("h4")))
return "h4";
if(isElementExist(driver, By.id("gw")))
return "gw";
if(isElementExist(driver, By.id("go")))
return "go";
if(isElementExist(driver, By.id("gg")))
return "gg";
return null;

}
4.写前端自动化的代码是非常不愉快的经历。
5.仍旧觉得前端自动化如不是实在绕不过去,别花太多精力。投入产出比太低了。

ding 回复

不同版本,不同 id 登录好像都有细微差别。猜测能热更新,并有各种灰度。坑不小。

本周微信热更了新的 X5,切换不好使了。chromedriver 拿不到 session 了。具体见这个贴:https://testerhome.com/topics/8990

高手碰到过不? @seveniruby @chenhengjie123

ding 回复

昨天改用 Java 也试了一下,同样只有一个 Native。然后,采用最新 1.6.5beta 版本偶然发现直接可以录制到 H5 内容。今天重新尝试似乎又不行了。好奇怪,配置没有发生任何变化。
如何保持 H5 一直显示状态?暂时没发现对应的调用入口。Java or .net

知行合一 回复

微信升了 H5 的内核。用 chromedriver 获取不了 session 了。

知行合一 回复

保持 H5 页面 一直显示,意思就是在只有一个 Native 时,把 H5 页面一直保持显示,关闭 appium 服务端,启动 uiautomatorviewer.bat ,查看被测试的 android h5 页面元素,就能看到 H5 页面元素,再用 appium 操作你想操作的元素,我这边是这样做的

刘晓光 回复

想问一下微信更了新的 X5,和微信的版本有关系么?

happymff 回复

你好,请问下 app WebView 的版本为 40.0.2214.124,这个版本太低了,以至于在 pom.xml 文件中把 Chromedriver 降低到 2.1 都没用,降到 2.1 会下载不到依赖,有什么方法提高 app WebView 的版本呢?

ding 回复

请问,H5 页面直接用 uiautomatorviewer 查看并操作,相当于用 Androiddriver 操作 H5 页面的元素,但是如果想从 H5 页面跳转到 native 页面,这时怎么操作?还需要 context 切换吗?我尝试了切换和不切换两种,都不能跳转到 native 页面,求帮助~

chen.zhou 回复

webview 就是个 apk,下载新的安装即可:
a. 更新 chromedriver
chromedriver 下载地址:https://chromedriver.storage.googleapis.com/index.html(连不上请 ***)

b. 更新手机里的 andriod.system.webview
webview 下载地址:https://www.apkmirror.com/apk/google-inc/android-system-webview/(连不上请 ***)

@happystone hi,我想问下,最先是我的 chrome 和 chromedriver 版本不一致导致切换 context 有问题,报 chrome not reachable 现在我已经把手机的 chrome 和 chromedriver 版本弄一致,但是又报其他错误
get context 得到 ["WEBVIEW_com.tencent.mm:appbrand0","WEBVIEW_com.tencent.mm:tools","WEBVIEW_com.tencent.mm:support","WEBVIEW_com.tencent.mm:appbrand1","WEBVIEW_com.android.quicksearchbox"]
日志打印的 chromeOptions
{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"ZPRWJREMM4NBL7"}}}
最后切换的时候总是报错 Device ZPRWJREMM4NBL7 is not online\n
info: JSONWP Proxy: Got response with status 200: {"sessionId":"bd50308685a46e4c369e386f881e9ab0","status":13,"value":{"message":"unknown error: Device ZPRWJREMM4NBL7 is not online\n (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3...
请问有没有什么好的解决方法,一直卡在着!

我在 switch context 时失败,Server 端 Log:

[Chromedriver] Set chromedriver binary as: /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver
[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver.*--port=8000"
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=8000 --adb-port=5037
[Chromedriver] [STDOUT] Starting ChromeDriver 2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f) on port 8000
Only local connections are allowed.
[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Mac OS X\",\"version\":\"10.12.5\"}}}"
[JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"androidProcess":"com.tencent.mm:tools","extensions":[],"androidDeviceSerial":"85GACME624JX"}}}
[JSONWP Proxy] Got response with status 200: {"sessionId":"82e6879e6b9151b7eabdde4e31307544","status":33,"value":{"message":"session not created exception: please close '' and try again\n  (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.5 x86_64)"}}
[JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"androidProcess":"com.tencent.mm:tools","extensions":[],"androidDeviceSerial":"85GACME624JX"}}}
[JSONWP Proxy] Got response with status 200: {"sessionId":"b185366db77d4ee0a616037f9fac3ec5","status":33,"value":{"message":"session not created exception: please close '' and try again\n  (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.5 x86_64)"}}
[JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"androidProcess":"com.tencent.mm:tools","extensions":[],"androidDeviceSerial":"85GACME624JX"}}}
[JSONWP Proxy] Got response with status 200: {"sessionId":"e09b925f60e70fc87c5a41084d9fd2a5","status":33,"value":{"message":"session not created exception: please close '' and try again\n  (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.5 x86_64)"}}
[JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"androidProcess":"com.tencent.mm:tools","extensions":[],"androidDeviceSerial":"85GACME624JX"}}}
[JSONWP Proxy] Got response with status 200: {"sessionId":"660d89bd2310fdd79d6bbf5421a03d36","status":33,"value":{"message":"session not created exception: please close '' and try again\n  (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.5 x86_64)"}}
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[Chromedriver] Changed state to 'stopped'
[Chromedriver] Error: session not created exception: please close '' and try again
  (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.5 x86_64)
    at Chromedriver.callee$2$0$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/lib/chromedriver.js:176:15)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
 Error: session not created exception: please close '' and try again
  (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.5 x86_64)
    at Chromedriver.callee$2$0$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/lib/chromedriver.js:176:15)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[MJSONWP] Encountered internal error running command: Error: session not created exception: please close '' and try again
  (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.5 x86_64)
    at Chromedriver.callee$2$0$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/lib/chromedriver.js:176:15)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)

有哪个同学知道这个问题怎么解决?

已解决,将 Appium 安装目录中的 chromedriver 版本替换为 chromedriver2.20 就可以了。
附上下载链接:https://chromedriver.storage.googleapis.com/index.html?path=2.20/

JamesChung 回复

老铁,为什么我用了 chromedriver2.20,还是报设备 is not online\n?哎,这个问题搞了一周多了,什么切换前杀 chromedriver 进程;
什么 chromedriver 和 webview 版本不一致,我从 2.9-2.32 全部装了一遍也不行,哎,想找一个完美解决啊,社区跟 webview 切换的帖子我都看了一遍,没有完美解决的,会有各种其他问题!

把日志贴出来啊,你是什么设备 is not online?

JamesChung 回复

NATIVE_APP,WEBVIEW_com.android.browser,WEBVIEW_com.tencent.mm:tools,WEBVIEW_com.tencent.mm:appbrand1,WEBVIEW_com.tencent.mm:support,WEBVIEW_undefined

info: [debug] ["WEBVIEW_com.android.browser","WEBVIEW_com.tencent.mm:tools","WEBVIEW_com.tencent.mm:appbrand1","WEBVIEW_com.tencent.mm:support","WEBVIEW_undefined"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.android.browser,WEBVIEW_com.tencent.mm:tools,WEBVIEW_com.tencent.mm:appbrand1,WEBVIEW_com.tencent.mm:support,WEBVIEW_undefined
info: [debug] Connecting to chrome-backed webview
info: Chromedriver: Changed state to 'starting'
info: Chromedriver: Set chromedriver binary as: D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
info: Chromedriver: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"9515 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %a))
info: Chromedriver: No old chromedrivers seemed to exist
info: Chromedriver: Spawning chromedriver with: D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=9515
info: Chromedriver: [STDOUT] Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 9515
Only local connections are allowed.
info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0\"}}}"
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"ZPRWJREMMJS4NBL7"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"fbe7450418f4b4a2cfe5ce0fe6f64b0d","status":13,"value":{"message":"unknown error: unable to discover open pages\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"ZPRWJREMMJS4NBL7"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"0d8c048f754b19dd9d48448b5c502f72","status":13,"value":{"message":"unknown error: unable to discover open pages\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"ZPRWJREMMJS4NBL7"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"37d665cf4e0c4b458285a826b02b83c6","status":13,"value":{"message":"unknown error: unable to discover open pages\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"ZPRWJREMMJS4NB"}}}
info: [debug] Didn't get a new command in 240 secs, shutting down...
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: D:\Android\android-sdk\platform-tools\adb.exe -s ZPRWJREMMJS4NB shell "input keyevent 3"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
info: [debug] [UIAUTOMATOR STDOUT] close [socket][/127.0.0.1:4724]
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 285.977
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] We shut down because no new commands came in
info: JSONWP Proxy: Got response with status 200: {"sessionId":"14c1e22e74ff1d7bd20c2c1567d06ad1","status":13,"value":{"message":"unknown error: unable to discover open pages\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081...
info: Chromedriver: Changed state to 'stopped'
error: Chromedriver: Chromedriver exited unexpectedly with code null, signal SIGTERM
warn: Chromedriver for context WEBVIEW_com.tencent.mm:tools stopped unexpectedly
warn: Chromedriver quit unexpectedly, but it wasn't the active context, ignoring
error: Chromedriver: Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: unable to discover open pages
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64))
at JWProxy.command$ (lib/proxy.js:133:15)
at tryCatch (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\regenerator\runtime.js:136:37)
at bound (domain.js:284:14)
at GeneratorFunctionPrototype.runBound (domain.js:297:12)
at run (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\node_modules\core-js\library\modules\es6.promise.js:89:39)
at D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\node_modules\core-js\library\modules\es6.promise.js💯28
at flush (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\node_modules\core-js\library\modules\$.microtask.js:17:13)
at process._tickDomainCallback (node.js:381:11)
{ [Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: unable to discover open pages
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64))]
status: 13,
value: { message: 'unknown error: unable to discover open pages\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64)' },
httpCode: 200 }
老铁,看哈哇,反正真机我各种问题都遇到过了,反正最后就是不能切换成功,我还说安卓搞好了,就用 mac 搞 ios 的,心好累,填了各种坑,还没有填平!

adfghzhang 回复

您好~请教下,我写上这三行代码,手机上就启动 chrome 浏览器,而不是启动微信呢?去掉这三行代码才能启动微信

@seveniruby 您好~请教下,我加上这三行代码
ChromeOptions options2 = new ChromeOptions();
options2.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
capabilities.setCapability(ChromeOptions.CAPABILITY, options2);
手机端就启动 chrome 浏览器,而不是启动微信呢?去掉这三行代码才能启动微信。appium 版本 1.4.16 JDK1.8 nodejs6.9.1

driver.context("WEBVIEW_com.tencent.mm:tools");
执行这句话的时候报错了,以下是 appium 的相关日志。po 或者各位老师能否帮忙看下?。。
A port was not given, using random port: 8000
然而其实是可以获取到 com.tencent.mm:tools 的 context 的,我的 appium 版本是 1.6.5

[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:support","WEBVIEW_com.tencent.mm:appbrand1","WEBVIEW_com.tencent.mm:tools","WEBVIEW_com.tencent.mm:appbrand0"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:tools'
[debug] [AndroidDriver] A port was not given, using random port: 8000
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: /usr/local/lib/node_modules/appium/node_modules/_appium-chromedriver@2.11.3@appium-chromedriver/chromedriver/mac/chromedriver
[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/usr/local/lib/node_modules/appium/node_modules/_appium-chromedriver@2.11.3@appium-chromedriver/chromedriver/mac/chromedriver.*--port=8000"
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: /usr/local/lib/node_modules/appium/node_modules/_appium-chromedriver@2.11.3@appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=8000 --adb-port=5037
[Chromedriver] [STDOUT] Starting ChromeDriver 2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f) on port 8000
Only local connections are allowed.
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Mac OS X\",\"version\":\"10.12.4\"}}}"
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"extensions":[],"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"GAY5H66999999999"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"5c952df12f67f053d65d69dd25346143","status":33,"value":{"message":"session not created exception: please close '' and try again\n (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.4 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"extensions":[],"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"GAY5H66999999999"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"a06ead138d2d9d9ddc24e5f86c6f1477","status":33,"value":{"message":"session not created exception: please close '' and try again\n (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.4 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"extensions":[],"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"GAY5H66999999999"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"977bc0c18832322475571c8df2cc1f68","status":33,"value":{"message":"session not created exception: please close '' and try again\n (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.4 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"args":[],"extensions":[],"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"GAY5H66999999999"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"f2b0918c492db7af976eb5f17f9a736c","status":33,"value":{"message":"session not created exception: please close '' and try again\n (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.4 x86_64)"}}
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[debug] [Chromedriver] Changed state to 'stopped'
[Chromedriver] Error: session not created exception: please close '' and try again
(Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.4 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:182:15)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:136:37)
Error: session not created exception: please close '' and try again
(Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.4 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:182:15)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:136:37)
[MJSONWP] Encountered internal error running command: Error: session not created exception: please close '' and try again
(Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.4 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:182:15)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:136:37)

daisychainsaw 回复

不好意思没有仔细看回复。。chromedriver 降级回 220 搞定。。。(第一次替换文件换错位置了。。应该替换这里的 /usr/local/lib/node_modules/appium/node_modules/_appium-chromedriver@2.11.3@appium-chromedriver/chromedriver/mac/

daisychainsaw 回复

nope。。。。。降级到 220.成功一次以后又不行了。。太淡腾了☹️

Got response with status 200: {"sessionId":"8ebf284e00bdf84b75a93169cdc80615","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Mac OS X 10.12.4 x86_64)"}}
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[debug] [Chromedriver] Changed state to 'stopped'
[Chromedriver] Error: chrome not reachable
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Mac OS X 10.12.4 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:182:15)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:136:37)
Error: chrome not reachable
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Mac OS X 10.12.4 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:182:15)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:136:37)
[MJSONWP] Encountered internal error running command: Error: chrome not reachable
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Mac OS X 10.12.4 x86_64)
at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:182:15)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:136:37)

请教一个问题,使用 node.js 来实现的时候,发现没有 selenium-webdriver 没有提供切换 webview 的相关方法,请问有使用 node.js 实现切换的吗?
我的环境如下:
node.js: v8.9.1
selenum-webdriver: 3.6.0
chromedriver: 2.34.0
appium: 1.7.1
代码如下:

let chrome = require('selenium-webdriver/chrome');

let { Builder } = require('selenium-webdriver');

let driver = new Builder().
    usingServer('http://localhost:4723/wd/hub').
    withCapabilities({
        platformName: 'Android',
        platformVersion: '6.0',
        deviceName: 'U10AFCPH235V8',   //魅族设备 U10
        appPackage: "com.tencent.mm",
        appActivity: ".ui.LauncherUI",
        fastReset: false,
        fullReset: false,
        noReset: true,
        androidProcess: 'com.tencent.mm:tools',
        browserName: 'com.tencent.mm'
    }).
    build();
driver.sleep(10000);
driver.findElement({ xpath: "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[4]/android.widget.LinearLayout" }).click();
driver.findElement({xpath:"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.LinearLayout/com.tencent.mm.ui.mogic.WxViewPager/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ListView/android.widget.LinearLayout[3]"}).click()
driver.findElement({xpath:"//android.widget.FrameLayout[@content-desc=\"当前所在页面,我的收藏\"]/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]"}).click();
driver.sleep(10000)

// 不能切换,没有找到相关切换webview的方法
driver.switchTo().activeElement("WEBVIEW_com.tencent.mm:tools")

参考文档 https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_TargetLocator.html

还有一个问题,同样我使用 python 来实现的过程中遇到如下问题 [Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[Chromedriver] Changed state to 'stopped'
看讨论里面说通过降级 chromedriver 可以实现,我降到 chromedriver 2.20 版本依然还是这个问题, 下面是我的代码,代码应该没毛病吧。

from appium import webdriver
import selenium

import time
desired_caps = {
    'platformName': 'Android',
    'fastReset': False,
    'deviceName': 'U10AFCPH235V8',
    'appPackage': 'com.tencent.mm',
    'appActivity': '.ui.LauncherUI',
    'fullReset': False,
    'unicodeKeyboard': False,
    'resetKeyboard': False,
    'noReset':True,
    'androidProcess' : 'com.tencent.mm:tools' 
    }

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(10)
el1 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[4]/android.widget.LinearLayout")
el1.click()
el2 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.LinearLayout/com.tencent.mm.ui.mogic.WxViewPager/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ListView/android.widget.LinearLayout[3]")
el2.click()
el3 = driver.find_element_by_xpath("//android.widget.FrameLayout[@content-desc=\"当前所在页面,我的收藏\"]/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]")
el3.click()
# current = driver.current_context
# contexts = driver.contexts
# print("len:",len(contexts))
time.sleep(5)
print("slepp for 5 secound....")
print(driver.contexts)
driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')

求助 please help me

请问各位,appium 能打开微信内置浏览器么?

再过来看看 哈哈

巫师师 回复

可以的。 参考我上面的代码可以打开微信浏览器。

137楼 已删除
qiqiqinqin 使用 Appium 测试微信小程序 Webview 中提及了此贴 02月23日 11:57
测试 回复

你好,我在小程序中遇到 chrome not reachable 的问题了,请问您当时怎么解决的?

笑哼 回复

是 chromedriver 的 bug,判断 webview 进程进行端口转发的时候没成功导致的。看下 chromdriver 的 log 就能分析明白了。

大家好,我也遇到了不能微信不能切换 webview 的问题,切换时一直卡主,我是用的 python,已经看了上面的的一些解决方法。也加了 desired_caps['chromeOptions']={'androidProcess': 'com.tencent.mm:tools'},以及尝试了各个 driver 版本。手机是安卓 6.0.
请问哪位同胞能给点相关的意见。
如下是代码,
from selenium.webdriver.support.wait import WebDriverWait
from appium import webdriver
from appium.webdriver.mobilecommand import MobileCommand
import time
desired_caps = {}
desired_caps['automationName']='Appium'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = 'R3E0216C10002466'
desired_caps['noReset'] = True
desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI'
desired_caps['chromeOptions']={'androidProcess': 'com.tencent.mm:tools'}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
print driver
time.sleep(10)
d1 = driver.find_element_by_xpath('//*[@text="我"]')
print d1
time.sleep(10)
a=driver.contexts

print a
print driver.current_context
driver.switch_to.context('WEBVIEW_com.tencent.mm:appbrand0')
print driver.current_context

---------------------如下是日志-------------------
[debug] [AndroidDriver] Returning process name: 'com.tencent.mm:support'
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_com.tencent.mm:tools","WEBVIEW_com.tencent.mm:appbrand0","WEBVIEW_com.tencent.mm:support"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:tools","WEBVIEW_com.tencent.mm:appbrand0","WEBVIEW_com.tencent.mm:support"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:appbrand0'
[debug] [AndroidDriver] A port was not given, using random port: 8000
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-chromedriver@3.4.0@appium-chromedriver\chromedriver\win\chromedriver.exe
[debug] [Chromedriver] Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"8000 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %a))
[Chromedriver] No old chromedrivers seemed to exist
[debug] [Chromedriver] Cleaning any old adb forwarded port socket connections
[debug] [ADB] List forwarding ports
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","R3E0216C10002466","forward","--list"]
[Chromedriver] Spawning chromedriver with: C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-chromedriver@3.4.0@appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=8000 --adb-port=5037 --verbose
[debug] [Chromedriver] Chromedriver version: '2.28.455520'
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.16299\"}}}"
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"R3E0216C10002466"}}}
[debug] [Chromedriver] Webview version: 'Chrome/57.0.2987.132'
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"45f1e1a238181e7412a59ee7ef6ebc90","status":13,"value":{"message":"unknown error: unable to discover open pages\n (Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 10.0.16299 x86_64)"}}
[Chromedriver] Error: Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. (Original error: unknown error: unable to discover open pages
Chromedriver)
[Chromedriver] at Object.wrappedLogger.errorAndThrow (../../lib/logging.js:78:13)
[Chromedriver] at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:217:13)
[Chromedriver] at tryCatch (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:67:40)
[Chromedriver] at GeneratorFunctionPrototype.invoke as _invoke
[Chromedriver] at GeneratorFunctionPrototype.prototype.(anonymous function) as throw
[Chromedriver] at GeneratorFunctionPrototype.invoke (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:136:37)
[Chromedriver] at
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"R3E0216C10002466"}}}
[debug] [Chromedriver] Webview version: 'Chrome/57.0.2987.132'

大佬好
环境: windows 10, appium 1.7.2, android 7(红米 note), python3.6, node 8.11,selenium 3.11 chromedriver 2.33, 手机 chrome 62
遇到的问题:
'在切换句柄的时候报错了,switch_to.context 报错信息如下:'
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Failed to start Chromedriver session: A new session could not be created. (Original error: session not created exception: please close 'com.zld.zld_face_rec_app' and try again
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.16299 x86_64))
需要的帮助
我想知道为什么会报这个错····目前提示服务起不了,让我关掉 我的 app 重启启动 ,感激不尽
代码 截图

不知道设置了哪里 我发现我不需要切换 webview 了 可以直接操作小程序里页面!!之前还一直找切换 webview 报错提示谷歌浏览器不可达,找原因找了好久 哈哈哈最后发现不知道怎么弄的设置 居然不需要切换 webview 了,代码如下:import sys
import os
import unittest
from time import sleep
from appium import webdriver

'''class TestAndorid(unittest.TestCase):

def setUp(self):
print('ready!')
def test_A(self):
print('A')
def tearDown(self):
print('end!')

'''
if name=='main':
#unittest.main()
desired_caps={}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.0.0'
desired_caps['appPackage']='com.tencent.mm'
desired_caps['appActivity']='.ui.LauncherUI'
#desired_caps['deviceName']='b955905d' #vivo 手机
desired_caps['deviceName']='UYT0218323001687'# 华为手机
#desired_caps['deviceName'] = 'ac27da9b' # 小米手机
desired_caps['app']=''
desired_caps["fastReset"]='False'
desired_caps['fullReset']='false' # 通过卸载程序的方式重置程序
desired_caps['noReset']='true' #Session 开始之前不重置程序状态
desired_caps['automationName']='appium'
desired_caps['chromeOptions']={'androidProcess':'com.tencent.mm:tools'}
#desired_caps['unicodeKeyboard']=True # 是否支持 unicode 键盘,输入中文设置 true
#desired_caps['resetKeyboard']=True # 是否重置键盘

url="http://127.0.0.1:4723/wb/hub"
driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub,desired_caps")
sleep(3)
print('进入微信点击发现前')
print(driver.contexts)
print(driver.current_context)
button1=driver.find_element_by_xpath("//[@text='发现']")
button1.click()
sleep(3)
print('进入微信点击发现后')
print(driver.contexts)
print(driver.current_context)
x=driver.get_window_size()['width']
y=driver.get_window_size()['height']
print(x,y)
driver.swipe(x/2,y*0.25,x/2,y*0.05,1000)
sleep(3)
driver.find_element_by_xpath("//
[@text='小程序']").click()
print('点击小程序后')
print(driver.contexts)
print(driver.current_context)
sleep(5)
driver.find_element_by_xpath("//[contains(@text,'美团外卖')]").click()
sleep(30)
print('点击美团后')
print(driver.contexts)
print(driver.current_context)
# driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
print('ok!!!!')
sleep(5)
driver.find_element_by_xpath("//
[@text='订单']").click()
print("已点")
sleep(5)
driver.quit()

我知道什么原因了,里面的还是需要切换 webview 元素。

这个报错是我切换 webview 时候报错

笑哼 回复

请问 谷歌浏览器不可达 问题 解决了吗

147楼 已删除

我使用华为 mate10 手机时候报错 谷歌浏览器不可达 即上面回答问题。在使用 vivo 手机和同样代码跑,就可以切换 webview,但是还找不到里面的元素,可能手机问题,希望能够帮助其他人, 但是我在使用 vivo 时候他找不到小程序里美团外卖的按钮,我使用的坐标点击策略目前,但是不是长久之计。

我昨天发现,点击美团小程序后不切换 webview,直接打印页面内容 print(driver.page_source) 如下:
....." bounds="[0,330][1080,876]" resource-id="" instance="12"><android.view.View index="1" text="" class="android.view.View" package="com.tencent.mm" content-desc="异国料理" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false.......
内容太长 我只截取一部分。
然后我要点击美团首页中的美食按钮,则使用 driver.find_element_by_xpath("//*[contains(@content-desc,'美食')]").click(),
可以完成点击。

在我切换 webview 后,所有可用 webview 内容均使用上面方法打印,未发现可用内容。

我的疑点是,现在做小程序自动化测试不需要切换 webview 了?不过上面打印页面内容 看不懂 不像网页 html 等等 如果使用 content-desc 这个标签就感觉不太靠谱 等等 疑点。

更新下我的最新代码,我发现可以不用切换 webview 但是,,这种办法是依赖 content-desc 属性值,也不太靠谱稳定。但是我找不到更好的办法,因为在尝试切所有的 webview 后 我找打印内容中均未发现我需要的内容,难道 driver.page_source 这句有问题 并不能输出页面完成内容? 下面为我的最新代码:
import sys
import os
import unittest
from time import sleep
from appium import webdriver

if name=='main':
#unittest.main()
desired_caps={}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.0.0'
#desired_caps['platformVersion'] = '7.1.1'
desired_caps['appPackage']='com.tencent.mm'
desired_caps['appActivity']='.ui.LauncherUI'
#desired_caps['deviceName']='b955905d' #vivo 手机
#desired_caps['recreateChromeDriverSessions'] = True 来回切换 webview
desired_caps['deviceName']='UYT0218323001687'# 华为手机
#desired_caps['deviceName'] = 'ac27da9b' # 小米手机
#desired_caps['app']=''
desired_caps["fastReset"]='False'
desired_caps['fullReset']='False' # 通过卸载程序的方式重置程序
desired_caps['noReset']='true' #Session 开始之前不重置程序状态
desired_caps['automationName']='appium'
desired_caps['chromeOptions'] = {'androidProcess': 'com.tencent.mm:appbrand1'}
#desired_caps['unicodeKeyboard']=True # 是否支持 unicode 键盘,输入中文设置 true
#desired_caps['resetKeyboard']=True # 是否重置键盘

url="http://127.0.0.1:4723/wb/hub"
driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub,desired_caps")
sleep(3)
print('进入微信点击发现前')
print(driver.contexts)
print(driver.current_context)
button1=driver.find_element_by_xpath("//[@text='发现']")
button1.click()
sleep(3)
print('进入微信点击发现后')
print(driver.contexts)
print(driver.current_context)
x=driver.get_window_size()['width']
y=driver.get_window_size()['height']
print(x,y)
driver.swipe(x/2,y*0.25,x/2,y*0.05,1000)
sleep(3)
driver.find_element_by_xpath("//
[@text='小程序']").click()
print('点击小程序后')
print(driver.contexts)
print(driver.current_context)
sleep(10)
driver.tap([(255,529),(459,598)],500)
#driver.find_element_by_xpath("//[contains(@text,'美团外卖')]").is_displayed()
#driver.find_element_by_xpath("//
[contains(@text,'美团外卖')]").click()
sleep(10)
print('点击美团后')
print(driver.page_source)
print(driver.contexts)
print(driver.current_context)
#driver.switch_to.context('WEBVIEW_com.tencent.mm:appbrand1')
sleep(10)
print('ok!!!!')
print(driver.current_context)
#print(driver.find_element_by_xpath("//"))
print(driver.page_source)
driver.find_element_by_xpath("//
[contains(@content-desc,'美食')]").click()
#driver.find_element_by_xpath("//[contains(@text,'美食')]").click()
# driver.find_element_by_xpath("//
[contains(@text,'首页')]").click()
# driver.find_element_by_xpath("/html/body/wx-view/wx-view/wx-swiper[1]/div/div[1]/div/wx-swiper-item[1]/wx-view[1]/wx-image/div").click()
print("已点")
sleep(5)
driver.quit()

Stepthen 回复

你好,请问如果是别的 app(不是 wechat),如何设置 androidProcess 呢?我获取的 webview 进程名只是"WEBVIEW_chrome"

我说一下我的问题哈,我自己的项目,使用普通的 WebView 可以找到元素,但使用 X5 WebView 就不行了。。这可能是什么问题?

你好 你在切换 webview 的时候有没有遇到过 chrome not reachable 问题

http 回复

chrome not reachable 问题解决了没有?

您好 我在做微信公众号自动化而时候也遇到 chrome not reachable,用的手机是华为荣耀 9 appium 版本 1.8.1

独行数息 回复

你好,刚开始学自动化,想问下这句'chromeOptions': {'androidProcess': 'com.tencent.mm:tools'} 是什么意思?

codeskyblue Android WebView 研究笔记 中提及了此贴 08月29日 18:31

请问各位大神有没有遇到过在这种问题,appium 识别不了 chromoption,代码与大神的一致

[BaseDriver] The following capabilities were provided, but are not recognized by appium: goog:chromeOptions.
[AndroidDriver] Error: The desired capabilities must include either 'appPackage' or 'browserName'

你好,我测试微信的时候,调用 handles = driver.window_handles 这行,报 selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: 404 - "unknown command: session/235ef6916d260840085786e7c871db68/window/handles"我用的是微信 6.6.7 版本

@balaroth 请问一下如何避免重复登录微信的操作呢?

郝斯文 uiautomator2 微信 webview 的自动化技术实操 中提及了此贴 10月25日 17:37
思寒_seveniruby 微信 webview 的自动化技术 中提及了此贴 11月29日 17:02
simple 专栏文章:[精华帖] 社区历年精华帖分类归总 中提及了此贴 12月13日 14:44
simple [精彩盘点] TesterHome 社区 2018 年 度精华帖 中提及了此贴 01月07日 12:08

请问一下,如何在微信公众号里面进行滑动操作呢?我使用之前封装的滑动方法(针对 APP 的)对微信公众号进行操作,提示我;Message: unknown error: operation is unsupported on Android,但是,安卓 APP 是可以成功运行的,这让我很困惑

求助: 本人用的模拟器,有办法解决没?

http 回复

同样的 chrome not reachable 的问题,如何解决

com.tencent.mm:appbrand3 请教下 这个值是怎么来的?

根据博主思路实现的微信客户端自动化供参考,附上 Github 源码实现:微信公众号文章采集之:微信自动化

另附上服务端公众号文章爬取和解析:微信公众号文章采集之:服务端数据采集

vanlong-nox 无法在 Android 上切换上下文 webview 中提及了此贴 05月09日 13:54

An unknown server-side error occurred while processing the command. Original error: A new session could not be created. Details: session not created exception: please close 'xxx' and try again

这个发生在 switch_to.context 时的报错有挺多人提的,没看到有回答的,有人解决了吗?

173楼 已删除

跟用什么 appium 版本无关。是 uiautomator2 做了解析转换,用原生也可以定位到。微信关闭了 webview 的调试特性,所以默认切不进去,需要 hack 下才行。

@ 思寒_seveniruby 楼主,你好,请问一下这个错误有什么解决方法吗?error: The desired should not include both of an 'appPackage' and a 'browserName'

176楼 已删除
TL-cj 回复

已解决
1、浏览器看不到设备或访问资源
确保打开 x5 内核调试开关
2、添加代码
ChromeOptions.setCapability("browserName","");

TL-cj 回复

@TL-cj H5 webdriver 版本与系统 chrome driver 版本不一致 问题解决了吗

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