python 使用appium實現京東搶購腳本3.0


此方法不比手動快,僅僅只是作為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()

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM