此方法不比手动快,仅仅只是作为appium的练手项目
import logging from appium import webdriver import time from appium.webdriver.common.mobileby import MobileBy from appium.webdriver.common.touch_action import TouchAction class TestXueQiu: def setup(self): caps = {} caps["platformName"] = "android" caps["deviceName"] = "ld" caps["appPackage"] = "com.jingdong.app.mall" caps["appActivity"] = "com.jingdong.app.mall.main.MainActivity" caps["chromedriverExecutable"] = r"E:\python\chromedriver.exe" caps["noReset"] = True caps["skipDeviceInitialization"] = True self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps) self.driver.implicitly_wait(20) def test_search(self): self.driver.find_element(MobileBy.XPATH,"//*[@content-desc='购物车1']").click() self.driver.tap([(80,2109),(140,2109),(120,2080)],500) # 全选购物车 actions = TouchAction(self.driver) actions.tap(x=120,y=2109) cycle=0 while True: actions.perform() if '去结算(1)' in self.driver.page_source: break else: self.driver.find_element(MobileBy.XPATH,"//*[@content-desc='购物车1']").click() time.sleep(1) cycle+=1 logging.warning("the {} time try buy".format(cycle)) self.driver.find_element(MobileBy.XPATH, "//*[contains(@content-desc,'去结算')]").click() self.driver.find_element(MobileBy.XPATH, "//*[contains(@text,'提交订单')]").click() def teardown(self): time.sleep(10) self.driver.quit()