{"id":79073,"date":"2026-02-28T23:04:51","date_gmt":"2026-02-28T15:04:51","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/79073.html"},"modified":"2026-02-28T23:04:51","modified_gmt":"2026-02-28T15:04:51","slug":"%e3%80%90ui%e8%87%aa%e5%8a%a8%e5%8c%96%e6%b5%8b%e8%af%95%e3%80%916_appium%e5%9f%ba%e7%a1%80api-_app%e5%9f%ba%e7%a1%80%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/79073.html","title":{"rendered":"\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u4e00\u3001\u5e94\u7528\u8df3\u8f6c\u3001\u83b7\u53d6\u5305\u540d\u754c\u9762\u540d<\/li>\n<li>\u4e8c\u3001 \u5173\u95edapp\u548c\u9a71\u52a8\u5bf9\u8c61<\/li>\n<li>\n<ul>\n<li>2.1 driver.close_app()\u5173\u95ed\u5e94\u7528<\/li>\n<li>2.2 driver.quit()\u5173\u95ed\u9a71\u52a8\u5bf9\u8c61<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001\u5b89\u88c5\u548c\u5378\u8f7d\u4ee5\u53ca\u662f\u5426\u5b89\u88c5app<\/li>\n<li>\u56db\u3001\u5c06\u5e94\u7528\u7f6e\u4e8e\u540e\u53f0<\/li>\n<li>\u4e94\u3001\u70ed\u542f\u52a8\u548c\u51b7\u542f\u52a8<\/li>\n<\/ul>\n<h2>\u4e00\u3001\u5e94\u7528\u8df3\u8f6c\u3001\u83b7\u53d6\u5305\u540d\u754c\u9762\u540d<\/h2>\n<p>\u9700\u6c42&#xff1a;\u6253\u5f00\u300a\u8bbe\u7f6e\u300b\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u7b49\u5f85\u4e09\u79d2\u540e\u8df3\u8f6c\u5230\u300a\u901a\u8baf\u5f55\u300b\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5e76\u8f93\u51fa\u5f53\u524d\u7684\u5305\u540d\u548c\u754c\u9762\u540d<\/p>\n<p><span class=\"token comment\"># \u2460\u5bfc\u5305<\/span><br \/>\n<span class=\"token keyword\">import<\/span> time<br \/>\n<span class=\"token keyword\">from<\/span> appium <span class=\"token keyword\">import<\/span> webdriver<\/p>\n<p><span class=\"token comment\"># \u2461\u914d\u7f6e\u542f\u52a8\u53c2\u6570<\/span><br \/>\ndesired_caps <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\"># \u624b\u673a\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;Android&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformVersion&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;5.1&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;deviceName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;1&#039;<\/span><br \/>\n<span class=\"token comment\"># \u5e94\u7528\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appPackage&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;com.android.settings&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appActivity&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;com.android.settings.Settings&#039;<\/span><\/p>\n<p><span class=\"token comment\"># \u2462 \u521b\u5efaAPP\u9a71\u52a8\u5bf9\u8c61<\/span><br \/>\ndriver <span class=\"token operator\">&#061;<\/span> webdriver<span class=\"token punctuation\">.<\/span>Remote<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;http:\/\/localhost:4723\/wd\/hub&#039;<\/span><span class=\"token punctuation\">,<\/span> desired_caps<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u2463 \u4e1a\u52a1\u64cd\u4f5c<\/span><br \/>\ntime<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># 1\u3001\u8df3\u8f6c\u5230\u901a\u8baf\u5f55<\/span><br \/>\ndriver<span class=\"token punctuation\">.<\/span>start_activity<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;com.android.contacts&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;.activities.PeopleActivity&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># 2\u3001\u7b49\u5f852s\u83b7\u53d6\u300a\u901a\u8baf\u5f55\u300b\u5305\u540d\u548c\u754c\u9762\u540d<\/span><br \/>\ntime<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u8f93\u51fa\u5f53\u524d\u7a0b\u5e8f\u7684\u5305\u540d<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>driver<span class=\"token punctuation\">.<\/span>current_package<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u8f93\u51fa\u5f53\u524d\u7a0b\u5e8f\u7684\u754c\u9762\u540d<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>driver<span class=\"token punctuation\">.<\/span>current_activity<span class=\"token punctuation\">)<\/span><\/p>\n<p>time<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u2464\u5173\u95edAPP<\/span><br \/>\ndriver<span class=\"token punctuation\">.<\/span>quit<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u7ed3\u679c &#xff1a;<\/p>\n<p>com.android.contacts<br \/>\n.activities.PeopleActivity<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260228150447-69a3040f2906a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u4e8c\u3001 \u5173\u95edapp\u548c\u9a71\u52a8\u5bf9\u8c61<\/h2>\n<p>\u9700\u6c42&#xff1a;\u6253\u5f00\u300a\u8bbe\u7f6e\u300b&#xff0c;\u4f7f\u7528 driver.close_app() \u65b9\u6cd5\u5173\u95ed&#xff0c;\u518d\u5c1d\u8bd5\u4f7f\u7528 driver.quit()\u65b9\u6cd5&#xff0c;\u6700\u540e\u6253\u5370\u5f53\u524d\u7a0b\u5e8f\u7684\u5305\u540d&#xff0c;\u89c2\u5bdf\u533a\u522b\u3002<\/p>\n<h3>2.1 driver.close_app()\u5173\u95ed\u5e94\u7528<\/h3>\n<p>\u628a\u300a\u8bbe\u7f6e\u300b\u6253\u5f00&#xff0c;\u8fc7\u4e863\u79d2\u53c8\u5173\u95ed\u4e86&#xff0c;\u73b0\u5728\u5728\u5b89\u5353\u624b\u673a\u7684\u684c\u9762\u3002\u2014\u2014&gt;\u4e4b\u540e\u6253\u5370\u5b89\u5353\u684c\u9762\u5e94\u7528<\/p>\n<p><span class=\"token keyword\">from<\/span> appium <span class=\"token keyword\">import<\/span> webdriver<br \/>\n<span class=\"token keyword\">import<\/span> time<\/p>\n<p>desired_caps <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u624b\u673a\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;Android&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformVersion&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;5.1&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;deviceName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;192.168.56.101:5555&#039;<\/span><br \/>\n<span class=\"token comment\"># \u5e94\u7528\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appPackage&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;com.android.settings&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appActivity&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;.Settings&#039;<\/span><\/p>\n<p><span class=\"token comment\"># \u83b7\u53d6driver<\/span><br \/>\ndriver <span class=\"token operator\">&#061;<\/span> webdriver<span class=\"token punctuation\">.<\/span>Remote<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;http:\/\/localhost:4723\/wd\/hub&#039;<\/span><span class=\"token punctuation\">,<\/span> desired_caps<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u7b49\u5f85\u4e09\u79d2<\/span><br \/>\ntime<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u5173\u95ed\u5e94\u7528<\/span><br \/>\ndriver<span class=\"token punctuation\">.<\/span>close_app<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6253\u5370\u5305\u540d<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>driver<span class=\"token punctuation\">.<\/span>current_package<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<p>com<span class=\"token punctuation\">.<\/span>android<span class=\"token punctuation\">.<\/span>launcher3  <span class=\"token comment\"># \u5b89\u5353\u624b\u673a\u5185\u90e8\u7684\u542f\u52a8\u5668<\/span><\/p>\n<h3>2.2 driver.quit()\u5173\u95ed\u9a71\u52a8\u5bf9\u8c61<\/h3>\n<p><span class=\"token keyword\">from<\/span> appium <span class=\"token keyword\">import<\/span> webdriver<br \/>\n<span class=\"token keyword\">import<\/span> time<\/p>\n<p>desired_caps <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u624b\u673a\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;Android&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformVersion&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;5.1&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;deviceName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;192.168.56.101:5555&#039;<\/span><br \/>\n<span class=\"token comment\"># \u5e94\u7528\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appPackage&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;com.android.settings&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appActivity&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;.Settings&#039;<\/span><\/p>\n<p><span class=\"token comment\"># \u83b7\u53d6driver<\/span><br \/>\ndriver <span class=\"token operator\">&#061;<\/span> webdriver<span class=\"token punctuation\">.<\/span>Remote<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;http:\/\/localhost:4723\/wd\/hub&#039;<\/span><span class=\"token punctuation\">,<\/span> desired_caps<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u7b49\u5f85\u4e09\u79d2<\/span><br \/>\ntime<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u9000\u51fadriver<\/span><br \/>\ndriver<span class=\"token punctuation\">.<\/span>quit<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6253\u5370\u5305\u540d<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>driver<span class=\"token punctuation\">.<\/span>current_package<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u7ed3\u679c&#xff1a;\u62a5\u9519\u3002driver\u76f8\u5f53\u4e8e\u7ba1\u5bb6\u4e00\u6837\u3002\u628a\u7ba1\u5bb6\u8f9e\u9000\u4e86&#xff0c;\u6ca1\u4eba\u5e72\u6d3b\u5f53\u7136\u62a5\u9519\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260228150448-69a304103423b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u4e09\u3001\u5b89\u88c5\u548c\u5378\u8f7d\u4ee5\u53ca\u662f\u5426\u5b89\u88c5app<\/h2>\n<p>\u9700\u6c42\u5173\u95ed\u8bbe\u7f6e\u5e94\u7528&#xff0c;\u7136\u540e\u5982\u679c\u300aqq\u300b\u5df2\u7ecf\u5b89\u88c5&#xff0c;\u5219\u5378\u8f7d\u300aqq\u300b&#xff0c;\u5982\u679c\u6ca1\u6709\u5219\u5b89\u88c5\u3002<\/p>\n<p><span class=\"token comment\"># \u2460\u5bfc\u5305<\/span><br \/>\n<span class=\"token keyword\">import<\/span> time<br \/>\n<span class=\"token keyword\">from<\/span> appium <span class=\"token keyword\">import<\/span> webdriver<\/p>\n<p><span class=\"token comment\"># \u2461\u914d\u7f6e\u542f\u52a8\u53c2\u6570<\/span><br \/>\ndesired_caps <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\"># \u624b\u673a\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;Android&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformVersion&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;5.1&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;deviceName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;1&#039;<\/span><br \/>\n<span class=\"token comment\"># \u5e94\u7528\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appPackage&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;com.android.settings&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appActivity&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;com.android.settings.Settings&#039;<\/span><\/p>\n<p><span class=\"token comment\"># \u2462 \u521b\u5efaAPP\u9a71\u52a8\u5bf9\u8c61<\/span><br \/>\ndriver <span class=\"token operator\">&#061;<\/span> webdriver<span class=\"token punctuation\">.<\/span>Remote<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;http:\/\/localhost:4723\/wd\/hub&#039;<\/span><span class=\"token punctuation\">,<\/span> desired_caps<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u2463 \u4e1a\u52a1\u64cd\u4f5c<\/span><br \/>\n<span class=\"token comment\"># 1\u3001\u5173\u95ed\u5f53\u524d\u6253\u5f00\u7684app&#xff08;\u8bbe\u7f6e\u5173\u95ed&#xff09;<\/span><br \/>\ndriver<span class=\"token punctuation\">.<\/span>close_app<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\ntime<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 2\u3001\u5224\u65ad\u624b\u673a\u662f\u5426\u5b89\u88c5qq\u53c2\u6570\u4e3a\u5305\u540d&#xff1b;\u5982\u679c\u5b89\u88c5&#xff0c;\u5c31\u8981\u5378\u8f7d<\/span><br \/>\n<span class=\"token keyword\">if<\/span> driver<span class=\"token punctuation\">.<\/span>is_app_installed<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;com.tencent.mobileqq&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    driver<span class=\"token punctuation\">.<\/span>remove_app<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;com.tencent.mobileqq&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3\u3001\u5982\u679c\u6ca1\u6709&#xff0c;\u5219\u5b89\u88c5.(\u672c\u5730\u5b89\u88c5\u5305\u7684\u5b8c\u6574\u8def\u5f84\u540d)<\/span><br \/>\n<span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    driver<span class=\"token punctuation\">.<\/span>install_app<span class=\"token punctuation\">(<\/span><span class=\"token string\">r&#034;C:\\\\Users\\\\ggk\\\\Desktop\\\\QQ.apk&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>time<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u2464\u5173\u95edAPP<\/span><br \/>\ndriver<span class=\"token punctuation\">.<\/span>quit<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260228150448-69a30410d30ab.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u56db\u3001\u5c06\u5e94\u7528\u7f6e\u4e8e\u540e\u53f0<\/h2>\n<p>\u9700\u6c42&#xff1a;\u6253\u5f00\u300a\u8bbe\u7f6e\u300b\u5e94\u7528&#xff0c;\u8fdb\u5165\u540e\u53f0 5 \u79d2&#xff0c;\u518d\u56de\u5230\u524d\u53f0<\/p>\n<p><span class=\"token keyword\">import<\/span> time<br \/>\n<span class=\"token keyword\">from<\/span> appium <span class=\"token keyword\">import<\/span> webdriver<\/p>\n<p>desired_caps <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u624b\u673a\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;Android&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;platformVersion&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;5.1&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;deviceName&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;192.168.56.101:5555&#039;<\/span><br \/>\n<span class=\"token comment\"># \u5e94\u7528\u53c2\u6570<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appPackage&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;com.android.settings&#039;<\/span><br \/>\ndesired_caps<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;appActivity&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;.Settings&#039;<\/span><\/p>\n<p><span class=\"token comment\"># \u83b7\u53d6driver<\/span><br \/>\ndriver <span class=\"token operator\">&#061;<\/span> webdriver<span class=\"token punctuation\">.<\/span>Remote<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;http:\/\/localhost:4723\/wd\/hub&#039;<\/span><span class=\"token punctuation\">,<\/span> desired_caps<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;&#8212;- \u51c6\u5907\u8fdb\u5165\u540e\u53f0 &#8212;-&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u8fdb\u5165\u540e\u53f05\u79d2&#xff0c;\u518d\u56de\u5230\u524d\u53f0<\/span><br \/>\ndriver<span class=\"token punctuation\">.<\/span>background_app<span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;&#8212;- \u5df2\u7ecf\u56de\u5230\u524d\u53f0 &#8212;-&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>time<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><br \/>\ndriver<span class=\"token punctuation\">.<\/span>quit<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260228150449-69a3041132431.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u4e94\u3001\u70ed\u542f\u52a8\u548c\u51b7\u542f\u52a8<\/h2>\n<p>1\u3001\u70ed\u542f\u52a8&#xff1a;\u8868\u793a\u8fdb\u5165\u540e\u53f0\u56de\u5230\u524d\u53f0\u3002<\/p>\n<p>2\u3001\u51b7\u542f\u52a8&#xff1a;\u5173\u673a\u518d\u5f00\u8fd9\u79cd\u5207\u65ad\u7535\u6e90\u7684\u884c\u4e3a\u53ef\u4ee5\u53eb\u505a \u201d\u51b7\u542f\u52a8\u201c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u76ee\u5f55\u4e00\u3001\u5e94\u7528\u8df3\u8f6c\u3001\u83b7\u53d6\u5305\u540d\u754c\u9762\u540d\u4e8c\u3001 \u5173\u95edapp\u548c\u9a71\u52a8\u5bf9\u8c612.1 driver.close_app()\u5173\u95ed\u5e94\u75282.2 driver.quit()\u5173\u95ed\u9a71\u52a8\u5bf9\u8c61\u4e09\u3001\u5b89\u88c5\u548c\u5378\u8f7d\u4ee5\u53ca\u662f\u5426\u5b89\u88c5app\u56db\u3001\u5c06\u5e94\u7528\u7f6e\u4e8e\u540e\u53f0\u4e94\u3001\u70ed\u542f\u52a8\u548c\u51b7\u542f\u52a8\u4e00\u3001\u5e94\u7528\u8df3\u8f6c\u3001\u83b7\u53d6\u5305\u540d\u754c\u9762\u540d<br \/>\n\u9700\u6c42&#xff1a;\u6253\u5f00\u300a\u8bbe\u7f6e\u300b\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u7b49\u5f85\u4e09\u79d2\u540e\u8df3\u8f6c\u5230\u300a\u901a\u8baf\u5f55\u300b\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5e76\u8f93\u51fa\u5f53\u524d\u7684\u5305\u540d\u548c\u754c\u9762\u540d<br \/>\n# \u2460\u5bfc\u5305<br \/>\nimport time<br \/>\nfrom appium import webdri<\/p>\n","protected":false},"author":2,"featured_media":79069,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3879,780],"topic":[],"class_list":["post-79073","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-appium","tag-ui"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/79073.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u76ee\u5f55\u4e00\u3001\u5e94\u7528\u8df3\u8f6c\u3001\u83b7\u53d6\u5305\u540d\u754c\u9762\u540d\u4e8c\u3001 \u5173\u95edapp\u548c\u9a71\u52a8\u5bf9\u8c612.1 driver.close_app()\u5173\u95ed\u5e94\u75282.2 driver.quit()\u5173\u95ed\u9a71\u52a8\u5bf9\u8c61\u4e09\u3001\u5b89\u88c5\u548c\u5378\u8f7d\u4ee5\u53ca\u662f\u5426\u5b89\u88c5app\u56db\u3001\u5c06\u5e94\u7528\u7f6e\u4e8e\u540e\u53f0\u4e94\u3001\u70ed\u542f\u52a8\u548c\u51b7\u542f\u52a8\u4e00\u3001\u5e94\u7528\u8df3\u8f6c\u3001\u83b7\u53d6\u5305\u540d\u754c\u9762\u540d \u9700\u6c42&#xff1a;\u6253\u5f00\u300a\u8bbe\u7f6e\u300b\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u7b49\u5f85\u4e09\u79d2\u540e\u8df3\u8f6c\u5230\u300a\u901a\u8baf\u5f55\u300b\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5e76\u8f93\u51fa\u5f53\u524d\u7684\u5305\u540d\u548c\u754c\u9762\u540d # \u2460\u5bfc\u5305 import time from appium import webdri\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/79073.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-28T15:04:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260228150447-69a3040f2906a.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/79073.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/79073.html\",\"name\":\"\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-28T15:04:51+00:00\",\"dateModified\":\"2026-02-28T15:04:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/79073.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/79073.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/79073.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/79073.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u76ee\u5f55\u4e00\u3001\u5e94\u7528\u8df3\u8f6c\u3001\u83b7\u53d6\u5305\u540d\u754c\u9762\u540d\u4e8c\u3001 \u5173\u95edapp\u548c\u9a71\u52a8\u5bf9\u8c612.1 driver.close_app()\u5173\u95ed\u5e94\u75282.2 driver.quit()\u5173\u95ed\u9a71\u52a8\u5bf9\u8c61\u4e09\u3001\u5b89\u88c5\u548c\u5378\u8f7d\u4ee5\u53ca\u662f\u5426\u5b89\u88c5app\u56db\u3001\u5c06\u5e94\u7528\u7f6e\u4e8e\u540e\u53f0\u4e94\u3001\u70ed\u542f\u52a8\u548c\u51b7\u542f\u52a8\u4e00\u3001\u5e94\u7528\u8df3\u8f6c\u3001\u83b7\u53d6\u5305\u540d\u754c\u9762\u540d \u9700\u6c42&#xff1a;\u6253\u5f00\u300a\u8bbe\u7f6e\u300b\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u7b49\u5f85\u4e09\u79d2\u540e\u8df3\u8f6c\u5230\u300a\u901a\u8baf\u5f55\u300b\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5e76\u8f93\u51fa\u5f53\u524d\u7684\u5305\u540d\u548c\u754c\u9762\u540d # \u2460\u5bfc\u5305 import time from appium import webdri","og_url":"https:\/\/www.wsisp.com\/helps\/79073.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-28T15:04:51+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260228150447-69a3040f2906a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/79073.html","url":"https:\/\/www.wsisp.com\/helps\/79073.html","name":"\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-28T15:04:51+00:00","dateModified":"2026-02-28T15:04:51+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/79073.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/79073.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/79073.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010UI\u81ea\u52a8\u5316\u6d4b\u8bd5\u30116_Appium\u57fa\u7840API _App\u57fa\u7840\u64cd\u4f5c"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/79073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=79073"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/79073\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/79069"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=79073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=79073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=79073"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=79073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}