Android端自动化小程序--增删账号

#代码前准备
#python -m uiautomator2 init
#python -m weditor
获取当前activity名:adb shell dumpsys window | findstr mCurrentFocus

import uiautomator2 as u2
import time

#熟悉基本功能
d = u2.connect('28084106100000116')
print(d.info)
print(d.serial)

d.screen_off()
time.sleep(3)
d.screen_on()
time.sleep(3)
#d.app_start('com.android.tv.settings')

d(resourceId="com.google.android.tvlauncher:id/settings")  #进入设置
time.sleep(1)
d.xpath('//*[@resource-id="com.google.android.tvlauncher:id/settings"]').click()  #进入WiFi设置

time.sleep(1)
d.xpath('//*[@resource-id="com.android.tv.settings:id/list"]/android.widget.LinearLayout[3]/android.widget.LinearLayout[1]').click()
time.sleep(1)         

d(resourceId="android:id/switch_widget").click()  #关闭WiFi开关
image = d.screenshot() # default format="pillow"
image.save("close.jpg")
d(resourceId="android:id/switch_widget").click()  #打开WiFi开关
image = d.screenshot() # default format="pillow"
image.save("open.jpg")

time.sleep(1)
d.press("home")
time.sleep(1)

d(resourceId="com.google.android.tvlauncher:id/inputs").click()
time.sleep(1)
d.xpath('//*[@resource-id="com.google.android.tvlauncher:id/list"]/android.widget.FrameLayout[1]').click()
time.sleep(3)
d.keyevent("adb shell input keyevent 23")
d.keyevent("adb shell input keyevent 22")
d.keyevent("adb shell input keyevent 23")
d.keyevent("adb shell input keyevent 23")
time.sleep(10)

d.press("home")
time.sleep(2)

if d.xpath('//*[@text="xm11"]').exists:
		print('Google account add successful')

#增删账号函数
def addGoogleaccount():
	d(resourceId="com.google.android.tvlauncher:id/settings").click() #进入设置
	time.sleep(2)

	d.xpath('//*[@text="Accounts & Sign-In"]').click()#进入Accounts&Sign-In
	time.sleep(2)

	#d.keyevent("adb shell input keyevent 20")
	#time.sleep(2)
	
	if (d.xpath('//*[@text="Add account"]').exists):
		d.xpath('//*[@text="Add account"]').click()#点击Add account
		time.sleep(2)
		
	d.xpath('//*[@text="Google"]').click()#点击Google
	time.sleep(2)
	
	#d.xpath('//*[@text="Sign In"]').click() 
	d.keyevent("adb shell input keyevent 23")  #点击sign in不成功,改成keyevent点击确定进入
	time.sleep(2)
	d.keyevent("adb shell input keyevent 23")
	time.sleep(2)
	d.keyevent("adb shell input keyevent 20")
	time.sleep(2)
	d.keyevent("adb shell input keyevent 23")
	time.sleep(10)
	
	d.xpath('//*[@resource-id="identifierId"]').wait(timeout=5.0)
	d.xpath('//*[@resource-id="identifierId"]').click()
	#d.xpath('//*[@resource-id="identifierId"]').clear_text()
	d.xpath('//*[@resource-id="identifierId"]').set_text('xxx')
	d.xpath('//*[@text="Next"]').click()
	time.sleep(5)
	
	d.xpath('//android.widget.EditText').click()
	d.xpath('//android.widget.EditText').wait(timeout=5.0)
	d.xpath('//android.widget.EditText').set_text('xxx')
	d.xpath('//*[@text="Next"]').click()
	time.sleep(10)

	if d.xpath('//*[@text="xxx@gmail.com"]').exists:
		print('Google account add successful')
		
		d.xpath('//*[@text="xxx@gmail.com"]').click()
		time.sleep(2)

		d.xpath('//*[@text="Remove account"]').click()
		time.sleep(2)
		
		d.xpath('//*[@resource-id="com.android.tv.settings:id/guidedactions_list"]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]').click()
		time.sleep()

if __name__=='__main__':
	addGoogleaccount()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值