本章主要讲:python实现一个登陆的自动化脚本
# -*-coding:utf8-*-
from time import sleep
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] ='Android'
desired_caps['platformVersion'] = '4.1.2'
desired_caps['deviceName'] = '42f6d2145170cfed'
desired_caps['appPackage'] = '****'
desired_caps['appActivity'] = '*****'
#被测试的App在电脑上的位置
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
#4725 4726 4723
sleep(3) #sleep()的作用,当网络时间差,页面加载不出来的时候,需要等待几秒,要不然找不到需要定位的组件,就会报错
driver.find_element_by_android_uiautomator('text("请输入手机号")').send_keys('13000000001') #element_by_android_uiautomator是定位方法,click()是点击方法
sleep(2)
mine=driver.find_elements_by_class_name("android.widget.EditText") #elements_by_class_name是定位方法
mine[1].click()
mine[1].send_keys("123456") #send_keys()自动输入方法
sleep(2)
driver.find_element_by_android_uiautomator('text("登录")').click()
思考:还有很多种定位方法,比如find_element_by_id()等,留给你们自己研究喽
更多用法集合大全,参考:https://testerhome.com/topics/3711
坑1:urllib2.URLError: urlopen error [Errno 61] Connection refused
解决方案:开启appium
坑2:
selenium和appium版本不匹配,把selenium从3.5降级到2.53.6就好了
执行:
pip uninstall selenium
pip install selenium==2.53.6
(注意是2个==,中间不要留空格,这里推荐的是2.53.6的版本)
坑3:error:No module named appium
第一次运行时可能会遇到这样的error:No module named appium
之所以会报这样的error是因为没有装client
解决方案:
cd /usr/local/bin
pip3 install Appium-Python-Client

3824

被折叠的 条评论
为什么被折叠?



