解决:切换context时报错selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command...

1|0报错


尝试写了一个切换上下文的代码,结果报错了

# context.py from appium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from appium.webdriver.common.mobileby import MobileBy import time desired_caps = {} desired_caps["platformName"] = "Android" desired_caps["platformVersion"] = "7.1.2" desired_caps["deviceName"] = "Android Simulator" desired_caps["appPackage"] = "com.lemon.lemonban" desired_caps["appActivity"] = ".activity.WelcomeActivity" driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) #元素定位 class_info_xpath = "//android.widget.TextView[@text='全程班']" WebDriverWait(driver, 10, 1).until(EC.visibility_of_element_located((MobileBy.XPATH, class_info_xpath))) driver.find_element_by_xpath(class_info_xpath).click() time.sleep(5) try: print("所有的上下文: ", driver.contexts) print("当前所在的上下文: ", driver.current_context) print("=========") #切换上下文 print("切换上下文") driver.switch_to.context(driver.contexts[-1]) print("当前所在的上下文: ", driver.current_context) print("=========") #切换默认的上下文 print("切回默认的上下文") driver.switch_to.context(None) print("当前所在的上下文: ", driver.current_context) except: driver.close_app() driver.close()


排查原因,才发现我的appium server上根本没装chromedriver,appium日志里也显示了这一点

[Chromedriver] at Object.wrappedLogger.errorAndThrow (C:\Users\beck\AppData\Roaming\npm\node_modules\appium\node_modules\appium-support\lib\logging.js:78:13) [Chromedriver] at Chromedriver.errorAndThrow [as start] (C:\Users\beck\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\lib\chromedriver.js:447:11) [debug] [W3C (95291239)] Encountered internal error running command: Error: No Chromedrivers found in 'C:\Users\beck\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win' [debug] [W3C (95291239)] at Object.wrappedLogger.errorAndThrow (C:\Users\beck\AppData\Roaming\npm\node_modules\appium\node_modules\appium-support\lib\logging.js:78:13) [debug] [W3C (95291239)] at Chromedriver.errorAndThrow [as start] (C:\Users\beck\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\lib\chromedriver.js:447:11) [HTTP] <-- POST /wd/hub/session/95291239-dc60-40f1-bbe6-96410fe06de4/context 500 459 ms - 843

2|0确定内置浏览器版本


2|1方法一


一般从应用信息里就能看出来版本,但我这里看不出来内核版本,所以才有第二种方法

2|2方法二


打开模拟器或者真机内置的浏览器,输入以下网址就可以查看版本: https://liulanmi.com/labs/core.html
可以看到是chrome v66,这时候去网站下载chromedriver v2.38,版本一定要一致

2|3方法三


还有一种方法是,在chrome浏览器中输入chrome://inspect,可以看到内置浏览器的版本信息

3|0替换chromedriver


去路径C:\Users\beck\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win下将下载的chromedriver替换掉

4|0再次运行


再次运行,就可以成功

5|0参考文章


《appium常见问题03_appium脚本报错selenium.common.exceptions.WebDriverException》


__EOF__

本文作者cnhkzyy
本文链接https://www.cnblogs.com/my_captain/p/12796590.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   cnhkzyy  阅读(13334)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示