解決:切換context時報錯selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command...


報錯

嘗試寫了一個切換上下文的代碼,結果報錯了

# 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

確定內置瀏覽器版本

方法一

一般從應用信息里就能看出來版本,但我這里看不出來內核版本,所以才有第二種方法

方法二

打開模擬器或者真機內置的瀏覽器,輸入以下網址就可以查看版本: https://liulanmi.com/labs/core.html
可以看到是chrome v66,這時候去網站下載chromedriver v2.38,版本一定要一致

方法三

還有一種方法是,在chrome瀏覽器中輸入chrome://inspect,可以看到內置瀏覽器的版本信息

替換chromedriver

去路徑C:\Users\beck\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win下將下載的chromedriver替換掉

再次運行

再次運行,就可以成功

參考文章

《appium常見問題03_appium腳本報錯selenium.common.exceptions.WebDriverException》


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 appium 報錯:selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Can't stop process; it's not currently runni... Appium(四) selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: You must include a platformName capability Appium問題解決方案(8)- selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not sign with default certificate. 報錯 An unknown server-side error occurred while processing the command的解決辦法 Appium異常:An unknown server-side error occurred while processing the command. Original error: Could n An unknown server-side error occurred while processing the command.處理 driver.startActivity 啟動app出現 An unknown server-side error occurred while processing the command appium報錯:An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: read ECONNRESET Win10上啟動UICrawler自動遍歷時報 "org.openqa.selenium.WebDriverException: An unknown server-side error occur red while processing the command. Original error: Could not sign with default certifi cate." Appium報錯: An unknown server-side error occurred while processing the command. Original error: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM