1.Appium 图像识别插件 images 安装 1 2 3 4 ➜ ~ appium plugin install images ✔ Checking if '@appium/images-plugin' is compatible ✔ Installing 'images' using NPM install spec '@appium/images-plugin' ℹ Plugin images@3.0.17 successfully installed
2.Appium 带着 images 插件启动 1 2 3 ➜ ~ appium --use-plugins=images [Appium] Attempting to load plugin images... [Appium] .........
3. 裁剪图片 (1)使用模拟器或者手机截图
(2)不改变尺寸大小和文件格式的情况下裁剪所要定位的图片
4.python🌰 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 from appium import webdriverfrom appium.options.android import UiAutomator2Optionsfrom appium.webdriver.common.appiumby import AppiumByimport base64capabilities = dict ( platformName='Android' , automationName='uiautomator2' , deviceName='xx' , ) appium_server_url = 'http://localhost:4723' driver = webdriver.Remote(appium_server_url, options=UiAutomator2Options().load_capabilities(capabilities)) with open ('images/p1.png' , 'rb' ) as image_file: image_data = image_file.read() encoded_image = base64.b64encode(image_data) encoded_image_str = encoded_image.decode('utf-8' ) driver.find_element(AppiumBy.IMAGE, encoded_image_str).click()
5. 相关参考 https://www.bilibili.com/video/BV1qt421M7kZ/?spm_id_from=333.999.0.0&vd_source=fd555860cd7cf9b09d9279e5deaabb9d