Appium Appium 关于微信 H5 页面切换 webview 的问题

zhouzhou123 · 2024年10月21日 · 最后由 微凉 回复于 2024年10月22日 · 4108 次阅读

Appium 进行微信小程序自动化测试,碰到切换 webview 后定位不到 H5 页面 元素问题
以下是我做的前提准备以及一些代码, 请问大神 哪里有问题?

1.打开微信调试功能
#1.打开微信调试功能
http://debugxweb.qq.com/?inspector=true
2.在电脑中安装 chromedriver
#2.在电脑中安装 chromedriver
帮我看看 我的 微信里面的 webview 版本号 122.0.6261.120 和 chromedriver 的版本号 120.0.6099.109 对应的关系对不对??

我这里安装的是这个版本,Version:120.0.6099.109(r1217362)

【chromedriver 下载链接地址:参考文献;https://zhuanlan.zhihu.com/p/657653897
手机上面查看
{
"user-agent": "Mozilla/5.0 (Linux; Android 9; V1941A Build/PKQ1.190302.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.120 Mobile Safari/537.36 XWEB/1220053 MMWEBSDK/20240404 MMWEBID/2626 MicroMessenger/8.0.49.2600(0x2800313D) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64"
}

3.以下是 python 和 appium 代码

aps = {}

         caps["platformName"] = "android"
         caps["deviceName"] = "aa"
         caps["appPackage"] = "com.tencent.mm"
         caps["appActivity"] =".ui.LauncherUI"
         caps['noReset']=True
         caps['unicodeKeyboard']=True
         caps['resetKeyboard']=True
         options = selenium.webdriver.ChromeOptions()
         options.add_experimental_option('androidProcess', 'com.tencent.mm:appbrand0')
         caps['ChromeOptions.CAPABILITY'] = 'options'
         caps['chromedriverExecutable']='D:\chromedriver-win64\chromedriver.exe'
         self._driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
         self._driver.implicitly_wait(10)

         # 尝试强制切换到 WebView 上下文
         try:
             self._driver.switch_to.context('WEBVIEW_com.tencent.mm:appbrand0')
             print(f"Current context: {self._driver.current_context}")
         except Exception as e:
             print(f"Failed to switch to WEBVIEW: {e}")
         time.sleep(10)  # 等待页面加载
         contexts = self._driver.contexts
         print(f"Available contexts: {contexts}")


           # 确认当前URL和Title
         current_url = self._driver.execute_script("return window.location.href;")
         current_title = self._driver.execute_script("return document.title;")
         print(f"Current URL: {current_url}")
         print(f"Current Title: {current_title}")

4.打印可用的 contexts 和当前的 WebView
这里可用的 contexts 有 2 个
Available contexts: ['NATIVE_APP', 'WEBVIEW_com.tencent.mm:appbrand0']
Current context: WEBVIEW_com.tencent.mm:appbrand0

5.尝试强制切换到 WebView 上下文后; 这里很奇怪 为什么 切换 WEBVIEW 后 查看当前可用的 contexts 有 3 个
Available contexts: ['NATIVE_APP', 'WEBVIEW_com.tencent.mm', 'WEBVIEW_com.tencent.mm:appbrand0']
Current context: WEBVIEW_com.tencent.mm:appbrand0

6.确认当前 URL 和 Title
current_url = self._driver.execute_script("return window.location.href;")
current_title = self._driver.execute_script("return document.title;")
print(f"Current URL: {current_url}")
print(f"Current Title: {current_title}")

以下是打印出来的结果
Current URL: https://servicewechat.com/preload/page-frame.html

Current Title:

  1. 这里是分析原因 https://servicewechat.com/preload/page-frame.html 是与微信小程序相关的 URL。这个链接指向的页面是微信小程序内部的一个预加载框架。微信小程序在运行时会加载这个页面作为基础架构的一部分,它通常包含小程序运行环境的初始代码和框架。这个页面不是用户直接访问的网页,而是微信小程序平台内部工作的一部分,用于支持小程序的渲染和功能。 微信小程序的工作原理是将各个页面的代码包在运行时动态加载到这个预加载框架中,从而实现小程序的页面切换和功能执行。因此,当你看到错误信息中提到这个 URL 时,通常意味着小程序在尝试加载或执行代码时遇到了问题,可能是由于资源加载失败、版本不匹配、代码错误或者是白名单配置不正确等原因导致的。

8.以下是 appium 日志
#

[HTTP] <-- GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/source 200 299 ms - 594
[HTTP]
[HTTP] --> GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/contexts
[HTTP] {}
[W3C (93535157)] Calling AppiumDriver.getContexts() with args: ["93535157-2cce-439e-b78c-4ca48e080be2"]
[AndroidDriver] Getting a list of available webviews
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 shell cat /proc/net/unix'
[AndroidDriver] Parsed 1 active devtools socket: ["@webview_devtools_remote_32198"]
[AndroidDriver] Collecting CDP data of 1 webview
[AndroidDriver] Forwarding remote port webview_devtools_remote_32198 to a local port in range 10900..11000
[AndroidDriver] You could use the 'webviewDevtoolsPort' capability to customize the starting port number
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward tcp:10900 localabstract:webview_devtools_remote_32198'
[ADB] Removing forwarded port socket connection: 10900
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward --remove tcp:10900'
[AndroidDriver] CDP data collection completed
[AndroidDriver] WEBVIEW_32198 mapped to pid 32198
[AndroidDriver] Getting process name for webview 'WEBVIEW_32198'
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 shell ps --help'
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 shell ps -A'
[AndroidDriver] Got process name: 'com.tencent.mm:appbrand0'
[AndroidDriver] Found 1 webview: ["WEBVIEW_com.tencent.mm:appbrand0"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:appbrand0"]
[W3C (93535157)] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_com.tencent.mm:appbrand0"]
[HTTP] <-- GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/contexts 200 1031 ms - 59
[HTTP]
[HTTP] --> POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/context
[HTTP] {"name":"WEBVIEW_com.tencent.mm:appbrand0"}
[W3C (93535157)] Calling AppiumDriver.setContext() with args: ["WEBVIEW_com.tencent.mm:appbrand0","93535157-2cce-439e-b78c-4ca48e080be2"]
[AndroidDriver] Getting a list of available webviews
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 shell cat /proc/net/unix'
[AndroidDriver] Parsed 1 active devtools socket: ["@webview_devtools_remote_32198"]
[AndroidDriver] Collecting CDP data of 1 webview
[AndroidDriver] Forwarding remote port webview_devtools_remote_32198 to a local port in range 10900..11000
[AndroidDriver] You could use the 'webviewDevtoolsPort' capability to customize the starting port number
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward tcp:10900 localabstract:webview_devtools_remote_32198'
[ADB] Removing forwarded port socket connection: 10900
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward --remove tcp:10900'
[AndroidDriver] CDP data collection completed
[AndroidDriver] WEBVIEW_32198 mapped to pid 32198
[AndroidDriver] Getting process name for webview 'WEBVIEW_32198'
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 shell ps -A'
[AndroidDriver] Got process name: 'com.tencent.mm:appbrand0'
[AndroidDriver] Found 1 webview: ["WEBVIEW_com.tencent.mm:appbrand0"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:appbrand0"]
[AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:appbrand0'
[AndroidDriver] A port was not given, using random free port: 8003
[AndroidDriver] Passing web view details to the Chromedriver constructor: {
[AndroidDriver] "info": {
[AndroidDriver] "Android-Package": "com.tencent.mm",
[AndroidDriver] "Browser": "Chrome/122.0.6261.120",
[AndroidDriver] "Protocol-Version": "1.3",
[AndroidDriver] "User-Agent": "Mozilla/5.0 (Linux; Android 9; V1941A Build/PKQ1.190302.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.120 Mobile Safari/537.36 XWEB/1220053 MMWEBSDK/20240404",
[AndroidDriver] "V8-Version": "12.2.281.22",
[AndroidDriver] "WebKit-Version": "537.36 (@user373203561d8d34ecaac0d)",
[AndroidDriver] "webSocketDebuggerUrl": "ws://127.0.0.1:10900/devtools/browser"
[AndroidDriver] },
[AndroidDriver] "process": {
[AndroidDriver] "name": "com.tencent.mm:appbrand0",
[AndroidDriver] "id": "32198"
[AndroidDriver] }
[AndroidDriver] }
[AndroidDriver] Precalculated Chromedriver capabilities: {
[AndroidDriver] "androidPackage": "com.tencent.mm",
[AndroidDriver] "androidUseRunningApp": true,
[AndroidDriver] "androidProcess": "com.tencent.mm:appbrand0",
[AndroidDriver] "androidDeviceSerial": "aa49af08"
[AndroidDriver] }
[AndroidDriver] Before starting chromedriver, androidPackage is 'com.tencent.mm'
[Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: D:\chromedriver-win64\chromedriver.exe
[Chromedriver] Killing any old chromedrivers, running: wmic process where "commandline like '%chromedriver.exe%--port=8003%'" delete
[Chromedriver] Successfully cleaned up old chromedrivers
[Chromedriver] Cleaning this device's adb forwarded port socket connections: aa49af08
[ADB] List forwarding ports
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward --list'
[ADB] Removing forwarded port socket connection: 55334
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward --remove tcp:55334'
[Chromedriver] Spawning chromedriver with: D:\chromedriver-win64\chromedriver.exe --url-base=wd/hub --port=8003 --adb-port=5037 --verbose
[Chromedriver] Chromedriver version: '122.0.6261.128'
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8003/wd/hub/status] with no body
[WD Proxy] Got response with status 200: {"value":{"build":{"version":"122.0.6261.128 (f18a44fedeb29764b2b5336c120fdd90ef1a3f5c-refs/branch-heads/6261@{#1057})"},"message":"ChromeDriver ready for new sessions.","os":{"arch":"x86_64","name":"Windows NT","version":"10.0.19044"},"ready":true}}
[Chromedriver] Starting W3C Chromedriver session with capabilities: {
[Chromedriver] "capabilities": {
[Chromedriver] "alwaysMatch": {
[Chromedriver] "goog:chromeOptions": {
[Chromedriver] "androidPackage": "com.tencent.mm",
[Chromedriver] "androidUseRunningApp": true,
[Chromedriver] "androidProcess": "com.tencent.mm:appbrand0",
[Chromedriver] "androidDeviceSerial": "aa49af08"
[Chromedriver] },
[Chromedriver] "goog:loggingPrefs": {
[Chromedriver] "browser": "ALL"
[Chromedriver] }
[Chromedriver] }
[Chromedriver] }
[Chromedriver] }
[WD Proxy] Matched '/session' to command name 'createSession'
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8003/wd/hub/session] with body: {"capabilities":{"alwaysMatch":{"goog:chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:appbrand0","androidDeviceSerial":"aa49af08"},"goog:loggingPrefs":{"browser":"ALL"}}}}
[Chromedriver] Webview version: 'Chrome/122.0.6261.120'
[WD Proxy] Got response with status 200: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"122.0.6261.120","chrome":{"chromedriverVersion":"122.0.6261.128 (f18a44fedeb29764b2b5336c120fdd90ef1a3f5c-refs/branch-heads/6261@{#1057})"},"fedcm:accounts":true,"goog:chromeOptions":{"debuggerAddress":"localhost:49741"},"pageLoadStrategy":"normal","platformName":"android","proxy":{},"setWindowRect":false,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:credBlob":false,"webauthn:extension:largeBlob":false,"webauthn:extension:minPinLength":false,"webauthn:extension:prf":false,"webauthn:virtualAuthenticators":false},"sessionId":"6b32cdbd1a1b226e93eec6104c18a90d"}}
[WD Proxy] Determined the downstream protocol as 'W3C'
[Chromedriver] Changed state to 'online'
[W3C (93535157)] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/context 200 3582 ms - 14
[HTTP]
[HTTP] --> GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/context
[HTTP] {}
[W3C (93535157)] Calling AppiumDriver.getCurrentContext() with args: ["93535157-2cce-439e-b78c-4ca48e080be2"]
[W3C (93535157)] Responding to client with driver.getCurrentContext() result: "WEBVIEW_com.tencent.mm:appbrand0"
[HTTP] <-- GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/context 200 1 ms - 44
[HTTP]
[HTTP] --> GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/contexts
[HTTP] {}
[W3C (93535157)] Calling AppiumDriver.getContexts() with args: ["93535157-2cce-439e-b78c-4ca48e080be2"]
[AndroidDriver] Getting a list of available webviews
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 shell cat /proc/net/unix'
[AndroidDriver] Parsed 2 active devtools sockets: ["@webview_devtools_remote_31937","@webview_devtools_remote_32198"]
[AndroidDriver] Collecting CDP data of 2 webviews
[AndroidDriver] Forwarding remote port webview_devtools_remote_31937 to a local port in range 10900..11000
[AndroidDriver] You could use the 'webviewDevtoolsPort' capability to customize the starting port number
[AndroidDriver] Forwarding remote port webview_devtools_remote_32198 to a local port in range 10900..11000
[AndroidDriver] You could use the 'webviewDevtoolsPort' capability to customize the starting port number
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward tcp:10900 localabstract:webview_devtools_remote_31937'
[ADB] Removing forwarded port socket connection: 10900
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward --remove tcp:10900'
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward tcp:10900 localabstract:webview_devtools_remote_32198'
[ADB] Removing forwarded port socket connection: 10900
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 forward --remove tcp:10900'
[AndroidDriver] CDP data collection completed
[AndroidDriver] WEBVIEW_31937 mapped to pid 31937
[AndroidDriver] Getting process name for webview 'WEBVIEW_31937'
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 shell ps -A'
[AndroidDriver] Got process name: 'com.tencent.mm'
[AndroidDriver] WEBVIEW_32198 mapped to pid 32198
[AndroidDriver] Getting process name for webview 'WEBVIEW_32198'
[ADB] Running 'C:\Users\junfei\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s aa49af08 shell ps -A'
[AndroidDriver] Got process name: 'com.tencent.mm:appbrand0'
[AndroidDriver] Found 2 webviews: ["WEBVIEW_com.tencent.mm","WEBVIEW_com.tencent.mm:appbrand0"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm","WEBVIEW_com.tencent.mm:appbrand0"]
[W3C (93535157)] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_com.tencent.mm","WEBVIEW_com.tencent.mm:appbrand0"]
[HTTP] <-- GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/contexts 200 1640 ms - 84
[HTTP]
[HTTP] --> GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/context
[HTTP] {}
[W3C (93535157)] Calling AppiumDriver.getCurrentContext() with args: ["93535157-2cce-439e-b78c-4ca48e080be2"]
[W3C (93535157)] Responding to client with driver.getCurrentContext() result: "WEBVIEW_com.tencent.mm:appbrand0"
[HTTP] <-- GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/context 200 1 ms - 44
[HTTP]
[HTTP] --> GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/source
[HTTP] {}
[W3C (93535157)] Driver proxy active, passing request on via HTTP proxy
[WD Proxy] Matched '/wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/source' to command name 'getPageSource'
[WD Proxy] Proxying [GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/source] to [GET http://127.0.0.1:8003/wd/hub/session/6b32cdbd1a1b226e93eec6104c18a90d/source] with no body
[WD Proxy] Got response with status 200: {"value":"
[HTTP] <-- GET /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/source 200 116 ms - 282721
[HTTP]
[HTTP] --> POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/execute/sync
[HTTP] {"script":"return window.location.href;","args":[]}
[W3C (93535157)] Calling AppiumDriver.execute() with args: ["return window.location.href;",[],"93535157-2cce-439e-b78c-4ca48e080be2"]
[WD Proxy] Matched '/execute/sync' to command name 'execute'
[Protocol Converter] Did not know how to rewrite the original URL '/execute/sync' for W3C protocol
[WD Proxy] Proxying [POST /execute/sync] to [POST http://127.0.0.1:8003/wd/hub/session/6b32cdbd1a1b226e93eec6104c18a90d/execute/sync] with body: {"script":"return window.location.href;","args":[]}
[WD Proxy] Got response with status 200: {"value":"https://servicewechat.com/preload/page-frame.html"}
[W3C (93535157)] Responding to client with driver.execute() result: "https://servicewechat.com/preload/page-frame.html"
[HTTP] <-- POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/execute/sync 200 79 ms - 61
[HTTP]
[HTTP] --> POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/execute/sync
[HTTP] {"script":"return document.title;","args":[]}
[W3C (93535157)] Calling AppiumDriver.execute() with args: ["return document.title;",[],"93535157-2cce-439e-b78c-4ca48e080be2"]
[WD Proxy] Matched '/execute/sync' to command name 'execute'
[Protocol Converter] Did not know how to rewrite the original URL '/execute/sync' for W3C protocol
[WD Proxy] Proxying [POST /execute/sync] to [POST http://127.0.0.1:8003/wd/hub/session/6b32cdbd1a1b226e93eec6104c18a90d/execute/sync] with body: {"script":"return document.title;","args":[]}
[WD Proxy] Got response with status 200: {"value":""}
[W3C (93535157)] Responding to client with driver.execute() result: ""
[HTTP] <-- POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/execute/sync 200 52 ms - 12
[HTTP]
[HTTP] --> POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element
[HTTP] {"using":"xpath","value":"//[@id=\"app\"]/div/div[2]/button/div/span"}
[W3C (93535157)] Driver proxy active, passing request on via HTTP proxy
[WD Proxy] Matched '/wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element' to command name 'findElement'
[WD Proxy] Proxying [POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element] to [POST http://127.0.0.1:8003/wd/hub/session/6b32cdbd1a1b226e93eec6104c18a90d/element] with body: {"using":"xpath","value":"//
[@id=\"app\"]/div/div[2]/button/div/span"}
[WD Proxy] Got response with status 404: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//[@id=\"app\"]/div/div[2]/button/div/span\"}\n (Session info: chrome=122.0.6261.120)","stacktrace":"\tGetHandleVerifier [0x00007FF614F6AD02+56930]\n\t(No symbol) [0x00007FF614EDF602]\n\t(No symbol) [0x00007FF614D942E5]\n\t(No symbol) [0x00007FF614DD98ED]\n\t(No symbol) [0x00007FF614DD9A2C]\n\t(No symbol) [0x00007FF614E1A967]\n\t(No symbol) [0x00007FF614DFBCDF]\n\t(No symbol) [0x00007FF614E181E2]\n\t(No symbol) [0x00007FF614DFBA43]\n\t(No symbol) [0x00007FF614DCD438]\n\t(No symbol) [0x00007FF614DCE4D1]\n\tGetHandleVerifier [0x00007FF6152E6F8D+3711213]\n\tGetHandleVerifier [0x00007FF6153404CD+4077101]\n\tGetHandleVerifier [0x00007FF61533865F+4044735]\n\tGetHandleVerifier [0x00007FF615009736+706710]\n\t(No symbol) [0x00007FF614EEB8DF]\n\t(No symbol) [0x00007FF614EE6AC4]\n\t(No symbol) [0x00007FF614EE6C1C]\n\t(No symbol) [0x00007FF614ED68D4]\n\tBaseThreadInitThunk [0x00007FF82004761...
[W3C] Matched W3C error code 'no such element' to NoSuchElementError
[HTTP] <-- POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element 404 112 ms - 1077
[HTTP]
[HTTP] --> POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element
[HTTP] {"using":"xpath","value":"//
[@id=\"app\"]/div/div[2]/button/div/span"}
[W3C (93535157)] Driver proxy active, passing request on via HTTP proxy
[WD Proxy] Matched '/wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element' to command name 'findElement'
[WD Proxy] Proxying [POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element] to [POST http://127.0.0.1:8003/wd/hub/session/6b32cdbd1a1b226e93eec6104c18a90d/element] with body: {"using":"xpath","value":"//[@id=\"app\"]/div/div[2]/button/div/span"}
[WD Proxy] Got response with status 404: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//
[@id=\"app\"]/div/div[2]/button/div/span\"}\n (Session info: chrome=122.0.6261.120)","stacktrace":"\tGetHandleVerifier [0x00007FF614F6AD02+56930]\n\t(No symbol) [0x00007FF614EDF602]\n\t(No symbol) [0x00007FF614D942E5]\n\t(No symbol) [0x00007FF614DD98ED]\n\t(No symbol) [0x00007FF614DD9A2C]\n\t(No symbol) [0x00007FF614E1A967]\n\t(No symbol) [0x00007FF614DFBCDF]\n\t(No symbol) [0x00007FF614E181E2]\n\t(No symbol) [0x00007FF614DFBA43]\n\t(No symbol) [0x00007FF614DCD438]\n\t(No symbol) [0x00007FF614DCE4D1]\n\tGetHandleVerifier [0x00007FF6152E6F8D+3711213]\n\tGetHandleVerifier [0x00007FF6153404CD+4077101]\n\tGetHandleVerifier [0x00007FF61533865F+4044735]\n\tGetHandleVerifier [0x00007FF615009736+706710]\n\t(No symbol) [0x00007FF614EEB8DF]\n\t(No symbol) [0x00007FF614EE6AC4]\n\t(No symbol) [0x00007FF614EE6C1C]\n\t(No symbol) [0x00007FF614ED68D4]\n\tBaseThreadInitThunk [0x00007FF82004761...
[W3C] Matched W3C error code 'no such element' to NoSuchElementError
[HTTP] <-- POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element 404 77 ms - 1077
[HTTP]
[HTTP] --> POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element
[HTTP] {"using":"xpath","value":"//[@id=\"app\"]/div/div[2]/button/div/span"}
[W3C (93535157)] Driver proxy active, passing request on via HTTP proxy
[WD Proxy] Matched '/wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element' to command name 'findElement'
[WD Proxy] Proxying [POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element] to [POST http://127.0.0.1:8003/wd/hub/session/6b32cdbd1a1b226e93eec6104c18a90d/element] with body: {"using":"xpath","value":"//
[@id=\"app\"]/div/div[2]/button/div/span"}
[WD Proxy] Got response with status 404: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//*[@id=\"app\"]/div/div[2]/button/div/span\"}\n (Session info: chrome=122.0.6261.120)","stacktrace":"\tGetHandleVerifier [0x00007FF614F6AD02+56930]\n\t(No symbol) [0x00007FF614EDF602]\n\t(No symbol) [0x00007FF614D942E5]\n\t(No symbol) [0x00007FF614DD98ED]\n\t(No symbol) [0x00007FF614DD9A2C]\n\t(No symbol) [0x00007FF614E1A967]\n\t(No symbol) [0x00007FF614DFBCDF]\n\t(No symbol) [0x00007FF614E181E2]\n\t(No symbol) [0x00007FF614DFBA43]\n\t(No symbol) [0x00007FF614DCD438]\n\t(No symbol) [0x00007FF614DCE4D1]\n\tGetHandleVerifier [0x00007FF6152E6F8D+3711213]\n\tGetHandleVerifier [0x00007FF6153404CD+4077101]\n\tGetHandleVerifier [0x00007FF61533865F+4044735]\n\tGetHandleVerifier [0x00007FF615009736+706710]\n\t(No symbol) [0x00007FF614EEB8DF]\n\t(No symbol) [0x00007FF614EE6AC4]\n\t(No symbol) [0x00007FF614EE6C1C]\n\t(No symbol) [0x00007FF614ED68D4]\n\tBaseThreadInitThunk [0x00007FF82004761...
[W3C] Matched W3C error code 'no such element' to NoSuchElementError
[HTTP] <-- POST /wd/hub/session/93535157-2cce-439e-b78c-4ca48e080be2/element 404 85 ms - 1077

共收到 2 条回复 时间 点赞

大概率是操作的目标页面错了,可以进 chrome://inspect 检查一下,应该切进哪个 web 页面进行操作才是对的,我们这边是直接过滤掉了 servicewechat.com 之类的非业务页面

微信有一个搜一搜的空白 web 页面,你切换到你自己那个 web 页面就行了

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