python appium實現企業微信自動打卡

2021-10-05 04:12:36 字數 3439 閱讀 2272

import time

def __init__(self, desired_caps, image_name):

self.url = ""

self.driver = webdriver.remote(self.url, desired_caps)

self.driver.implicitly_wait(10)

self.desired_caps = desired_caps

self.image_name = image_name

def clock_in(self):

time.sleep(10)

self.driver.find_element_by_android_uiautomator('new uiselector().text("工作台")').click()

time.sleep(10)

self.driver.find_element_by_android_uiautomator('new uiselector().text("打卡")').click()

time.sleep(10)

self.driver.get_screenshot_as_file(self.image_name+".png")

self.driver.lock(10)

self.driver.quit()

支援多台手機打卡,

devicelist 打卡終端

receiverlist  收件郵箱

2個list 順序必須對應

from datetime import datetime

import random

import time

note3 =

mix2 =

print("start!!!!!", datetime.now())

devicelist = ["mix2", "note3"]

receiverlist = ["******@sina.cn", "******[email protected]"]

try:

while true:

if datetime.now().isoweekday() not in (6, 7): # 判斷不為週末

if datetime.now().time().hour in (9, 18, 19): # 判斷當前小時數

if datetime.now().time().minute >= random.randint(20, 50) or datetime.now().time().minute >= 50:

print("啟動。。。。。。。。。。。。")

for i in range(len(devicelist)):

print(devicelist[i])

desired_caps = (eval(devicelist[i]))

sendmail.send_email(receiverlist[i], "成功!,%s" % datetime.now(), devicelist[i])

print("完成")

time.sleep(120)

time.sleep(3600)

time.sleep(60)

continue

time.sleep(120)

print("不滿足條件............未完成", datetime.now())

time.sleep(600)

except exception as e:

print("失敗", e)

# sendmail.send_email(receiverlist[0], "警告:打卡失敗!!!!,%s" % datetime.now(), "devicelist")

# clock_in.clock_in(note3, "note3",47230)

郵件

sender 發件郵箱

pwd 密碼

import smtplib

from email.mime.text import mimetext

from email.mime.multipart import mimemultipart

from email.mime.image import mimeimage

def send_email(receiver, msg_info, image_name):

host = 'smtp.163.com'

# 設定發件伺服器位址

port = 465

# 設定發件伺服器端口號。注意,這裡有ssl和非ssl兩種形式,現在一般是ssl方式

sender = '***[email protected]'

# 設定發件郵箱,一定要自己註冊的郵箱

pwd = '******x'

# 設定發件郵箱的授權碼密碼,根據163郵箱提示,登入第三方郵件客戶端需要授權碼

receiver = receiver

# 設定郵件接收人,可以是qq郵箱

# 設定郵件正文,這裡是支援html的

# msg = mimetext(msg, 'html')

msg = mimemultipart()

msg.attach(mimetext(msg_info, 'plain', 'utf-8'))

# 設定正文為符合郵件格式的html內容

msg['subject'] = '打**知'

# 設定郵件標題

msg['from'] = sender

# 設定傳送人

msg['to'] = receiver

# 設定接收人

with open(image_name+".png", 'rb') as picatt:

msgimg = mimeimage(picatt.read())

msgimg.add_header('content-disposition', 'attachment', filename=image_name+".png")

# msgimg.add_header('content-id', '<0>')

# msgimg.add_header('x-attachment-id', '0')

msg.attach(msgimg)

try:

s = smtplib.smtp_ssl(host, port)

# 注意!如果是使用ssl埠,這裡就要改為smtp_ssl

s.login(sender, pwd)

# 登陸郵箱

s.sendmail(sender, receiver, msg.as_string())

# 傳送郵件!

print('done.sent email success')

except smtplib.smtpexception:

print('error.sent email fail')

Python Appium 實現上下左右滑動螢幕

實現較為累贅,可以把獲取螢幕size,width,height 屬性作為公共屬性單抽出來,不過不影響使用 還有可以優化的地方,try except 沒有起到我預期的效果,暫時先留著 import time from mocirepatinet import phoneset import trace...

Python Appium實現滑動引導頁進入APP

1 建立session 2 運用 模擬手指從右向左滑動的操作 獲取螢幕寬度和高度 def getsize self x self.driver.get window size width y self.driver.get window size height return x,y 向左滑動 def...

python appium實現頁面元素的滑動

畢竟,比較熟悉robotframework這個工具。現在在複習python語言,就搞半天。思路有,函式用swipe,也知道。頁面就是不滑動,有點尷尬了。函式也沒有什麼錯誤,最後發現錯在自己在頁面上找的元素的思路上。思路確定後,就找到他們各自的座標就可以了。總結 思路沒有錯,動手執行後,問題就解決了。...