前言
用appium切換webview的時候報chrome和chromedriver版本的問題:session not created exception: Chrome version must be >= 58.0.3029.0
(Driver info: chromedriver=2.30.477700 )
運行環境:
android 7.0
appium 1.7.1
appium里面chromedriver 2.28
webview版本 57.0
遇到問題
1.當執行switch_to.context('WEBVIEW_NAME')這句代碼的時候,會報chrome瀏覽器和chromedriver不匹配,代碼報錯信息如下:
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: session not created exception: Chrome version must be >= 58.0.3029.0
(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)
2.查看appium的日志,很顯然是因為版本號不匹配導致的
{"sessionId":"54f24f2451884a7fdcc64fc6480c4a91","status":33,"value":{"message":"session not created exception: Chrome version must be >= 58.0.3029.0\n (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[Chromedriver] Changed state to 'stopped'
[Chromedriver] Unable to automate Chrome version because it is too old for this version of Chromedriver.
[Chromedriver] Please see 'https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/chromedriver.md'
[Chromedriver] Error: session not created exception: Chrome version must be >= 58.0.3029.0
3.那么問題來了,這個chrome版本到底是手機上chrome瀏覽器版本還是電腦上chrome瀏覽器版本,還是哪里的版本號呢?這個chromedriver又是哪的驅動版本?
查看webview版本號
1.以微信為例,webview的版本號可以用chrome瀏覽器查看到,由於微信用的是x5內核,跟其他app不太一樣,這里需要先開啟微信的debug模式
開啟微信debug模式:在微信聊天界面輸入:debugx5.qq.com,如何勾選"打開TBS內核Inspector調試功能
2.查看微信里面webview版本,直接在電腦chrome瀏覽器輸入:chrome://inspect/#devices
再打開微信的公眾號頁面,刷新瀏覽器頁面,就會出現webview版本號57.0
chromedrive下載
1.找到webview的chrome版本號了,接下來下載對應的chromedriver驅動包就可以了,57的webview對應2.28驅動
下載地址:chromedriver版本下載
2.chromedriver下載后應該放哪呢?首先找到報錯里面的chromedriver=2.30.477700 版本是從哪里來的,替換掉就可以了。查找路徑:\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win
找到后雙擊就能顯示版本號,chromedriver=2.30.477700也就是報錯里面看到的
備注:版本不一樣,路徑可能不太一樣,自己搜索:appium-chromedriver
3.把剛才下載2.28版本的chromedriver.exe替換掉這個2.30版本就可以了
在學習過程中有遇到疑問的,可以appium+python QQ群交流:330467341