python appium 坐标定位并且输入文本_python+appium来完成叠蛋糕任务

本文介绍如何使用Python配合Appium实现618活动任务自动化处理。通过详细步骤指导读者安装必要的软件,如Java、Android SDK及Appium,并提供配置教程。文章还展示了如何录制操作并生成Python代码。
部署运行你感兴趣的模型镜像

一年一度的618活动来了,每天做任务确实有点无聊,网上一查果然有攻略,鉴于本人使用python,那就用python来开发一个程序来完成任务吧。

环境准备

  • JAVA

下载地址:https://www.oracle.com/cn/java/technologies/javase-downloads.html

  • ANDROID SDK

下载地址:https://www.androiddevtools.cn/

  • appium

下载地址:http://appium.io/

安装文档自行百度或者google,有问题可以在评论中说

环境测试

打开命令行,

(1)输入java -version 如下输出说明java环境已经正常

e0720cdb5927445eb574ba85e6398a3b

(2)数据adb device list

注意:手机连接到电脑,并且确认已经打开开发者模式

210c0987126a4475b107cba47fe85797

如果报错说明android jdk安装有问题,请根据安装文档进行操作

appium流程演示:

(1)打开appium,进行host、port、java和Android jdk配置

e3c870bc55354b5ebcbb9bac5d3cc507

然后点下边那个保存并重启的按钮,然后点第一个Start Server按钮,将会看到:

9cc77f7e82354b92be04bfb1d8c6af1b

(2)点击Start Inspector Session

b1db0c32d7d1467b8553f01fb8907918

(3)根据下图进行配置

c56bfe095fad4352b42e7fbdbf2f976f

注意:标蓝色框一定要注意,不加的话会重新安装app

platformName :声明是ios还是Android系统

platformVersion : Android内核版本号,可通过命令adb shell getprop ro.build.version.release查看

(4)运行Start Session,选择元素

0bad9683f22442dea5490eb483753ca7

右侧 Selected Element 区域有三个按钮

  • Tap:执行选中元素的点击事件
  • Send Keys:为文本框等对象传值
  • 如果是文本输入元素,就清除文本

(5)开始录制,生成代码

adb44c128314458da6c8b969108b8cb3

(6)编写代码

2630f0b109014c6d955569e6219599f3

主要代码见上图,剩下的就把生成的代码复制过来就可以了,如果有问题评论见哈

附上一哥们的appium文档(有坑):https://www.cnblogs.com/jyd0124/archive/2020/03/23/appium.html

您可能感兴趣的与本文相关的镜像

Python3.9

Python3.9

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

自动化个人学习第一步笔记import os import time import logging import configparser from appium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait base_path=os.path.abspath(os.path.dirname(os.path.dirname(__file__))) class comm: @staticmethod def driver(): """APPIUM驱动""" desired_caps={} desired_caps['platformName']=comm.conf(section='desired_caps',key='platformName') # 手机操作系统 desired_caps['deviceName']=comm.conf(section='desired_caps',key='deviceName') # 手机设备号 desired_caps['platformVersion']=comm.conf(section='desired_caps',key='platformVersion') # 操作系统版本 desired_caps['appPackage']=comm.conf(section='desired_caps',key='appPackage') # app包名 desired_caps['appActivity']=comm.conf(section='desired_caps',key='appActivity') # app ACTIVITY名称 desired_caps['resetKeyboard']=True # 是否在测试结束后将键盘重轩为系统默认的输入法。 desired_caps['newCommandTimeout']=comm.conf(section='desired_caps',key='newCommandTimeout') # Appium服务器待appium客户端发送新消息的时间。默认为60秒 desired_caps['noReset'] = True # true:不重新安装APP,false:重新安装app desired_caps['automationName'] = comm.conf(section='desired_caps',key='automationName') # appium1.5以后的版本才支持toast定位 driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) return driver @staticmethod def get_element(driver,by,selector): """ description:封装定位方法;id指的是resource-id,class_name指的是class,uiautomator使用方法:'new UiSelector().text("文字内容")',xpath定位元素 uthor:clay date: 2020-5-08 params: driver 驱动,by 选择定位的方式,selector 定位的语法 """ if by == 'id': element=driver.find_element_by_id(selector) elif by =='class_name': element=driver.find_element_by_class_name(selector) elif by =='uiautomator': element=driver.find_elemen_by_android_uiautomator(selector) elif by == 'xpath': element=driver.find_element_by_xpath(selector) else: raise NameError return element @staticmethod def tap(driver,upper_left_x,upper_left_y,bottom_right_x,bottom_right_y,time): """ description:根据坐标触发点击事件 uthor:clay date: 2020-5-08 params: driver:驱动,upper_left_x:左上角坐标X轴,upprt_lef_y:左上角Y轴,bottom_right_x:右下角X轴,bottom_right_y:右下角Y轴,time:点击停留的时间 ms为单位 """ tap_=driver.tap([(upper_left_x,upper_left_y),(bottom_right_x,bottom_right_y)],time) return tap_ @staticmethod def tips(driver, text): """ descirption:xpath定位toast提示 author:supper date: 2029-10-06 params: text:元素的text文本 """ try: toast_loc = ("xpath", "//*[contains(@text,'%s')]" % text) toast = WebDriverWait(driver, 5, 0.1).until(EC.presence_of_element_located(toast_loc)) text = toast.text print('提示为:%s' % text) return True except: return False
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值