(Python)App自动化之日期滑动(带年月日)

def splid_data(self,year,month,day):
ele = self.driver.find_element(By.XPATH,"//*[contains(@text,‘确认’)]")
if ele!=None:
#元素的宽
width = ele.size[‘width’]
# 元素的高
height = ele.size[‘height’]
# 控件相对于整个屏幕的高度
y = ele.location[‘y’]
self.switchWebContext()
action = TouchAction(self.driver)

        if year !=0:
            defaultYear = self.driver.find_element(By.XPATH, "//*[@class='van-ellipsis' and contains(text(),'年')]")
            diffYear = int(defaultYear.get_attribute("innerText").replace(" 年", "")) - year
            diffYear = abs(diffYear)
            for item in range(1,abs(diffYear)+1):
                action.press(x=width / 6,y = y + height * 13 / 20).wait(500).move_to(x=width / 6,y=y + height * 62 / 100).release().perform()
                sleep(2)
        if int(month) !=0:
            defaultMonth = self.driver.find_element(By.XPATH, "//*[@class='van-ellipsis' and contains(text(),'月')]")
            diffMonth = int(defaultMonth.get_attribute("innerText").replace(" 月", "")) - int(month)
            for item in range(1, abs(diffMonth) + 1):
                action.press(x=width * 3 / 6, y = y + height * 13 / 20).wait(500).move_to(x=width * 3 / 6, y=y + height * 62 / 100).release().perform()
                sleep(2)
        if int(day)!=0:
            defaultDay = self.driver.find_element(By.XPATH, "//*[@class='van-ellipsis' and contains(text(),'日')]")
            diffDay = int(defaultDay.get_attribute("innerText").replace(" 日", "")) - int(day)
            for item in range(1, abs(diffDay) + 1):
                action.press(x=width * 5 / 6, y = y + height * 13 / 20).wait(500).move_to(x=width * 5 / 6, y=y + height * 62 / 100).release().perform()
                sleep(2)
    self.driver.switch_to.context("NATIVE_APP")
    self.SPDBBankButtonClick('确认',1)




@classmethod
def switchWebContext(self):
    contexts = self.driver.contexts
    print(contexts)
    logger.info(f"当前页面的context:{contexts}")
    for item in contexts:
        if item.startswith('WEBVIEW'):
            self.driver.switch_to.context(item)
            print("切换webview成功")
            now = self.driver.current_context
            logger.info(f"切换后的context:{now}")
            break






@classmethod
def SPDBBankButtonClick(self, text, textIndex):

    try:
        a = datetime.now()
        xpath = f'//*[normalize-space(@text)="{text}"]';
        xpath = xpath + "[last()]" if textIndex == -1 else xpath + "[" + str(textIndex) + "]"
        self.wait(xpath)
        self.click(By.XPATH, xpath)
        b = datetime.now()
        senconds = (b - a).seconds
        print("按钮点击耗时" + str(senconds) + "秒")
        print("点击按钮【" + text + "】成功")
    except:
        print("点击失败")
        raise



@classmethod
def click(self, locator, value):
    self.driver.find_element(locator, value).click();


@classmethod
def wait(self,loc):
    try:
        WebDriverWait(self.driver, 20, 0.5).until(EC.visibility_of_element_located((By.XPATH, loc)))
    except Exception as e:
        print(f"元素 不存在{loc}")
        raise
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值