视频教程:前言_哔哩哔哩_bilibili
文档地址:Appium原理与安装 | 白月黑羽
获取包名命令:
adb shell dumpsys activity recents | find "intent={"
抓取元素定位工具【androidsdk中】
AndroidSdk目录\tools\bin
还有一个定位工具【Appium Inspector】
会打开一个github链接去下载
Releases · appium/appium-inspector · GitHub
所需环境:python、androidsdk、jdk、appium
Appium官网:Release v1.22.3-4 · appium/appium-desktop · GitHub
示例代码:
from appium import webdriver
from selenium.webdriver.common.by import By
from appium.webdriver.extensions.android.nativekey import AndroidKey
desired_caps = {
'platformName': 'Android', # 被测手机是安卓
'platformVersion': '8', # 手机安卓版本
'deviceName': 'xxx', # 设备名,安卓手机可以随意填写
'appPackage': 'tv.danmaku.bili', # 启动APP Package名称
'appActivity': '.ui.splash.SplashActivity', # 启动Activity名称
'unicodeKeyboard': True, # 使用自带输入法,输入中文时填True
'resetKeyboard': True, # 执行完程序恢复原来输入法
'noReset': True, # 不要重置App
'newCommandTimeout': 6000,
'automationName' : 'UiAutomator2'
# 'app': r'd:\apk\bili.apk',
}
# 连接Appium Server,初始化自动化环境
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# 设置缺省等待时间
driver.implicitly_wait(5)
# 如果有`青少年保护`界面,点击`我知道了`
iknow = driver.find_elements(By.ID, "text3")
if iknow:
iknow.click()
# 根据id定位搜索位置框,点击
driver.find_element(By.ID, 'expand_search').click()
# 根据id定位搜索输入框,点击
sbox = driver.find_element(By.ID, 'search_src_text')
sbox.send_keys('白月黑羽')
# 输入回车键,确定搜索
driver.press_keycode(AndroidKey.ENTER)
# 选择(定位)所有视频标题
eles = driver.find_elements(By.ID, 'title')
for ele in eles:
# 打印标题
print(ele.text)
input('**** Press to quit..')
driver.quit()
相关问题:
1、夜神无法使用sdk中的定位工具
将sdk中的adb.exe替换掉夜神中的adb.exe、nox_adb.exe