怎么使用Appium打开淘宝APP,查找首页的扫一扫按钮并点击?
以下是使用Appium和Python代码打开淘宝APP并点击首页的扫一扫按钮:
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 定义 desired capabilities
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '9'
desired_caps['deviceName'] = 'your_device_name'
desired_caps['udid'] = 'your_device_udid'
desired_caps['appPackage'] = 'com.taobao.taobao'
desired_caps['appActivity'] = 'com.taobao.tao.TBMainActivity'
desired_caps['noReset'] = True
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
# 连接Appium server
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# 查找扫一扫按钮并点击
wait = WebDriverWait(driver, 10)
scan_button = wait.until(EC.presence_of_element_located((By.ID, 'com.taobao.taobao:id/home_searchbar')))
TouchAction(driver).tap(scan_button).perform()
# 关闭driver
driver.quit()
需要注意的是,需要替换your_device_name
和your_device_udid
为你使用的Android设备的名称和UDID。同时,需要确保手机中安装了淘宝APP,并且Appium server已经启动。