用appium 进行Webview测试时报错:An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: 404 - ""

代码

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait


class TestAppiumWebview:
    def setup(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['automationName'] = 'UiAutomator2'
        desired_caps['platformVersion'] = '6.0'
        desired_caps['deviceName'] = '127.0.0.1:7555'
        # desired_caps['browserName'] = 'Browser'
        desired_caps['appPackage'] = 'com.xueqiu.android'
        desired_caps['appActivity'] = 'com.xueqiu.android.common.MainActivity'
        desired_caps['noReset'] = 'true'
        desired_caps['dontStopAppOnReset'] = 'true'
        desired_caps['autoGrantPermissions'] = 'true'
        desired_caps['unicodeKeyBoard'] = 'true'
        desired_caps['resetKeyBoard'] = 'true'
        # 当需要输入中文时需要添加的两个选项
        self._driver = webdriver.Remote('127.0.0.1:4724/wd/hub', desired_caps)
        self._driver.implicitly_wait(10)

    def test_webview(self):

        self._driver.find_element(MobileBy.XPATH,'//*[@resource-id="com.xueqiu.android:id/tab_name" and @text="交易"]').click()
        locator = (MobileBy.XPATH, '//android.view.View[@content-desc="A股开户"]')
        WebDriverWait(self._driver, 20).until(expected_conditions.element_to_be_clickable(locator))

        self._driver.find_element(*locator).click()
        print("dayin")
        print(self._driver.window_handles)
        
        print("sss")

server报错

appium-server-logs.txt (49.4 KB)


看日志的提示信息,SDK 里面的 build-tools/ 路径下 有个30版本的, 更新一下,把30版本卸载掉,下载28或者29版本的。
参照链接: https://ceshiren.com/t/topic/4001

然后卸载 uiautomator-server ,执行下面命令,再重新执行脚本,让appium 重新运行自动安装 io.appium.uiautomator2.server io.appium.uiautomator2.server

adb uninstall io.appium.uiautomator2.server
adb uninstall io.appium.uiautomator2.server.test

重新运行脚本安装的时候先把 下在这俩设置去掉

desired_caps['noReset'] = 'true'
desired_caps['dontStopAppOnReset'] = 'true'  

默认端口不是4723嘛

我两边改成4723了也是这个错

老师,我按照你的来弄还是会报那个错误

错误

appium-server-logs1.txt (41.2 KB)

这回报错信息跟原来不一样了,这回是没找到元素, 要想找webview元素,必须先切换到webview的上下文,参照 webview录播视频那一章的代码

要想操作webview元素,以及获取window_handles 必须在webview的上下文中操作。

这个错误因为没有进入到web下的context,调用了window_handles方法