Failed to Dump Window Hierarchy","status":13"

本文介绍了一个Selenium在Android5.0上遇到的问题:“An unknown server-side error occurred while processing the command”,并分享了通过更换为Android7.0设备解决问题的经验。

问题描述

Selenium error: An unknown server-side error occurred while processing the command. Original error: Failed to Dump Window Hierarchy",“status”:13

相关issue:https://github.com/appium/appium/issues/4151

在Android5.0报错后换成Android7.0设备,OK啦

C:\own\app\python_code\.venv\Scripts\python.exe C:\own\app\python_code\work\IPL_click_all\full_automation.py 🚀 启动 Android 应用探索器... 🔧 正在处理初始化流程... 🔍 检测是否需要接受用户协议... 📄 检测到【用户协议】页面 👇 协议未读完,开始滚动... ✅ 第 3 次滑动后发现可点击的【I agree】按钮 📌 正在等待页面跳转... ❌ 第 3 次滑动后点击【I agree】无效,仍在原页面 ✅ 第 4 次滑动后发现可点击的【I agree】按钮 📌 正在等待页面跳转... ❌ 第 4 次滑动后点击【I agree】无效,仍在原页面 ✅ 第 5 次滑动后发现可点击的【I agree】按钮 📌 正在等待页面跳转... ❌ 第 5 次滑动后点击【I agree】无效,仍在原页面 ✅ 第 7 次滑动后发现可点击的【I agree】按钮 📌 正在等待页面跳转... ✅ 成功跳转出协议页面 ✅ 用户协议处理完成 🖨️ 检测是否进入【打印机选择】页面... ✅ 进入打印机选择页面 👋 用户中断执行。 🔚 自动化结束。 Process finished with exit code -1 def handle_user_agreement(self): print("🔍 检测是否需要接受用户协议...") try: initial_activity = self.driver.current_activity except: initial_activity = None try: # 等待协议页面出现 WebDriverWait(self.driver, 10).until( EC.presence_of_element_located(( 'xpath', '//*[contains(@text, "License") or contains(@text, "Agreement") or contains(@text, "user")]' )) ) print("📄 检测到【用户协议】页面") def find_agree_button(): candidates = [ '//*[@text="I agree"]', '//*[@text="Agree"]', '//*[contains(@resource-id, "yes")]', '//*[contains(@resource-id, "agree")]', ] for xpath in candidates: try: btn = self.driver.find_element(By.XPATH, xpath) if btn.is_displayed() and btn.is_enabled() and self.is_fully_active(btn): return btn except: continue return None # 先尝试直接点击 agree_btn = find_agree_button() if agree_btn: print("✅ 发现可点击的【I agree】按钮") current_act_before = self.driver.current_activity agree_btn.click() time.sleep(3) if self.driver.current_activity != current_act_before: print("✅ 已跳转至新页面,协议处理完成") return True else: print("🟡 点击了【I agree】但未跳转,可能需滚动") # 开始滚动 print("👇 协议未读完,开始滚动...") last_click_failed_id = None for i in range(10): size = self.driver.get_window_size() x = size['width'] // 2 y_start = int(size['height'] * 0.8) y_end = int(size['height'] * 0.3) self.driver.swipe(x, y_start, x, y_end, 600) time.sleep(1.5) agree_btn = find_agree_button() if not agree_btn: continue # 防止重复点击同一个无效按钮 if hasattr(agree_btn, 'id') and agree_btn.id == last_click_failed_id: continue print(f"✅ 第 {i + 1} 次滑动后发现可点击的【I agree】按钮") current_act_before = self.driver.current_activity agree_btn.click() print("📌 正在等待页面跳转...") time.sleep(3) try: WebDriverWait(self.driver, 10).until( lambda d: d.current_activity != current_act_before ) print("✅ 成功跳转出协议页面") return True except: print(f"❌ 第 {i + 1} 次滑动后点击【I agree】无效,仍在原页面") last_click_failed_id = agree_btn.id # 记录失败 ID # 兜底:UiAutomator 强制查找 clickable=true 的按钮 try: final_btn = self.driver.find_element( By.ANDROID_UIAUTOMATOR, 'new UiSelector().textContains("agree").enabled(true).clickable(true)' ) final_btn.click() print("🪄 使用 UiAutomator 强制点击【I agree】") time.sleep(3) if self.driver.current_activity != initial_activity: print("✅ 强制点击后成功跳转") return True except Exception as e: print(f"❌ UiAutomator 点击失败: {e}") return False except TimeoutException: print("🟢 未检测到用户协议页面,跳过") return True except Exception as e: print(f"⚠️ 用户协议处理异常: {type(e).__name__}: {e}") return False def is_fully_active(self, button): """判断按钮是否处于完全激活状态""" try: alpha = button.get_attribute("alpha") if alpha and float(alpha) < 0.8: return False except: pass try: class_name = button.get_attribute("class") if "disabled" in class_name.lower(): return False except: pass return True i agree变成可点击后会从灰色变为蓝色,增加is_full的判别
最新发布
10-18
09-12 13:40:03.860 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.config.IRadioConfig/default, status: -2 09-12 13:40:03.861 radio 3829 3829 D QtiLinkBandwidthEstimator-1: isDataPacketsCaluclationOnEachSimSeperately : true 09-12 13:40:03.862 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.data.IRadioData/slot1, status: -2 09-12 13:40:03.863 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.data.IRadioData/slot2, status: -2 09-12 13:40:03.865 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.messaging.IRadioMessaging/slot1, status: -2 09-12 13:40:03.866 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.messaging.IRadioMessaging/slot2, status: -2 09-12 13:40:03.868 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.modem.IRadioModem/slot1, status: -2 09-12 13:40:03.869 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.modem.IRadioModem/slot2, status: -2 09-12 13:40:03.870 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.network.IRadioNetwork/slot1, status: -2 09-12 13:40:03.871 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.network.IRadioNetwork/slot2, status: -2 09-12 13:40:03.872 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.sap.ISap/slot1, status: -2 09-12 13:40:03.873 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.sap.ISap/slot2, status: -2 09-12 13:40:03.874 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.sim.IRadioSim/slot1, status: -2 09-12 13:40:03.875 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.sim.IRadioSim/slot2, status: -2 09-12 13:40:03.875 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.voice.IRadioVoice/slot1, status: -2 09-12 13:40:03.876 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.radio.voice.IRadioVoice/slot2, status: -2 09-12 13:40:03.877 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.secure_element.ISecureElement/SIM1, status: -2 09-12 13:40:03.878 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.secure_element.ISecureElement/SIM2, status: -2 09-12 13:40:03.879 shell 12357 12357 E dumpstate: Failed to start dump thread for service: android.hardware.secure_element.ISecureElement/eSE1, status: -2
09-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值