解释:webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)

#coding=utf-8

from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = '02743107C5002344'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator'

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)

driver.find_element_by_name('2').click()
driver.find_element_by_name('0').click()
driver.find_element_by_name('1').click()
driver.find_element_by_name('8').click()

driver.quit()

1、'http://127.0.0.1:4723/wd/hub’

127.0.0.1和localhost代表本机。
4723是端口号,不是固定的,可以修改为没有被占用的端口号。
在cmd命令中可以查询到:

  • netstat -ano查看所有端口占用
    >netstat -ano
  • netstat -ano | findstr “4723” 查看4723端口号被哪个程序占用
    >netstat -ano | findstr “4723”
    在Appium可以修改端口号,同时也要修改代码中的端口号
    Appium

2、/wd/hub

wd:可以理解是WebDriver的缩写
hub:是指主节点、中心节点


版权声明:本文为xiaocai5731原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。