环境搭建:Windows 7 64bit

  • jdk包:jdk-8u171-windows-x64.exe(http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
  • 安卓sdk:adt-bundle-windows-x86_64-20140702(https://developer.oculus.com/documentation/mobilesdk/0.6/concepts/mobile-dev-setup-android-win/)
  • appium:1.4.13.1(https://bitbucket.org/appium/appium.app/downloads/)
  • node.js:node-v4.4.7-x64(https://nodejs.org/en/download/23)
  • Appium-Python-Client

1、安装好jdk,sdk,根据安装的位置设置环境变量,

jdk:

JAVA_HOME------C:\Program Files\Java\jdk1.8.0_171

PATH------;%JAVA_HOME%\bin\;%JAVA_HOME%\jre\bin\;

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

sdk:

解压adt-bundle-windows-x86_64-20140702.zip

ANDROID_HOME------C:\Users\dell\Downloads\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk

PATH------;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools\;

PATH------;%ANDROID_HOME%\build-tools\android-4.4W\;

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

测试

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

2、安装node.js

设置环境变量

PATH------C:\Program Files\nodejs\

测试

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

3、appium

appium是用.net开发的,所以需要安装.net framework4.5,下载地址:https://www.microsoft.com/zh-cn/download/details.aspx?id=3065332

appium-doctor:appium安装好后,找到这个文件目录C:\Program Files (x86)\Appium\node_modules\.bin;设置环境变量

PATH------C:\Program Files (x86)\Appium\node_modules\.bin;

测试

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

4、Appium-Python-Client

pip install Appium-Python-Client

5、安装夜神模拟器

6、测试用程序打开夜神模拟器中的微信

下载微信安装包weixin667android1320.apk,安装到夜神浏览器中

aapt dump badging D:\weixin667android1320.apk

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

获取到appPackage和appActivity

adb devices

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

获取到deviceName

编写Python程序

#coding=utf-8
from appium import webdriver
desired_caps = {
'platformName':'Android',
'deviceName':'127.0.0.1:62001',
'platformVersion':'4.4.2',
'appPackage':'com.tencent.mm',
'appActivity':'com.tencent.mm.ui.LauncherUI'
} driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)

启动appium,右上角点三角形按钮,变成正方形,就是启动状态。

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

运行Python程序,可以看到夜神模拟器多了两个应用

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

之后打开了微信

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

7、元素定位

将夜神的nox_adb.exe复制重命名替换掉sdk文件夹里的adb.exe

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

启动uiautomatorviewer.bat

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

单击Device Screenshot便可以定位元素,右上框显示元素的定位

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

注意,如果打开页面包含Appium Setting 和Unlock两个应用会报错

appium+夜神模拟器+python安卓app爬虫初体验-LMLPHP

04-28 04:53