You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Appium Android遇AttributeError:WebDriver无launch_app属性问题

解决Appium Python Client 3.x中launch_app()/close()方法不存在的问题

问题根源

你遇到的AttributeError是因为Appium Python Client 3.0+进行了API重构,原有的launch_app()、close_app()等Appium专属方法不再直接挂载在WebDriver实例上,而是调整了调用方式。

解决方案

针对你的需求(关闭并重启APP),有两种可行的实现方式:

方式1:使用Mobile JSON Wire Protocol命令(推荐)

这是Appium 3.x官方推荐的调用方式,直接执行移动端专属命令:

  • 重启APP(替代launch_app()):
def launching_iAkaun_Application(driver):
    # 传入你的appPackage作为appId
    driver.execute_script("mobile: launchApp", {"appId": "com.epf.mip.uat"})
  • 关闭APP(替代close()):
driver.execute_script("mobile: closeApp")

方式2:通过appium_driver属性调用原方法

如果你习惯旧版的方法调用形式,可以通过driver.appium_driver获取Appium原生驱动实例,再调用原有方法:

def launching_iAkaun_Application(driver):
    driver.appium_driver.launch_app()

关闭APP则用:

driver.appium_driver.close_app()

额外的代码优化提示

你的测试类中self.driver可能未正确初始化,建议调整测试代码:

@pytest.mark.usefixtures("appium_android_driver")
class TestSuite_EPF_Android_App:
    def setup_method(self, appium_android_driver):
        # 在setup中初始化driver实例
        self.driver = appium_android_driver

    def test_initialAppLaunch(self):
        launching_iAkaun_Application(self.driver)

或者直接在测试方法中使用fixture参数:

def test_initialAppLaunch(self, appium_android_driver):
    launching_iAkaun_Application(appium_android_driver)

内容的提问来源于stack exchange,提问作者SNAO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 04:10:18