1.手势方法
#手势方法######################################################################
# 在wlan元素上做一次轻敲
el = driver.find_element(MobileBy.XPATH, "//*[@text='WLAN']")
# 1 实例化touch_action对象
touch_action = TouchAction(driver)
# 2 调用手势方法后 perform执行
touch_action.press(el).wait(2000).release().perform()
time.sleep(1)
# 按下wifi元素2s后抬起
wifi_el = driver.find_element(MobileBy.XPATH, "//*[@text='wireless']")
touch_action.press(wifi_el).wait(2000).release().perform()
time.sleep(3)
# 即传入元素,也传入坐标, 点击的位置是相对于元素的坐标偏移量
# 定位开启文本坐标偏移 x=200, y=350后轻触
return_el = driver.find_element(MobileBy.XPATH, "//*[@text='开启']")
TouchAction(driver).tap(return_el, x=200, y=350).perform()
time.sleep(3)
# 找到安全元素
loc = MobileBy.XPATH, "//*[@text='安全']"
swipe_find_el(driver, loc)
driver.find_element(MobileBy.XPATH, "//*[@text='屏幕锁定方式']").click()
driver.find_element(MobileBy.XPATH, "//*[@text='图案']").click()
# 设置屏幕解锁的图案
touch_action = TouchAction(driver)
touch_action.press(x=135, y=505).move_to(x=405, y=505).wait(1000).\
move_to(x=675, y=505).wait(1000).move_to(x=675, y=775).wait(1000)\
.move_to(x=675, y=1045).release().perform()
2.手机设置
#手机设置######################################################################
# 获取屏幕分辨率
print(driver.get_window_size())
# 获取截图
filepath = os.path.dirname(os.path.abspath(__file__)) + '/day8/day09/' + "test.png"
driver.get_screenshot_as_file(filepath)
time.sleep(3)
for i in range(3):#音量增加
driver.press_keycode(25)
driver.find_element(MobileBy.XPATH, "//*[@text='WLAN']").click()
time.sleep(1)#返回键
driver.press_keycode(4)
time.sleep(1)
# 应⽤场景:需要获取通知栏的相关信息
# API语法:driver.open_notifications()
driver.open_notifications()
time.sleep(2)#通知栏和home
driver.press_keycode(3)
time.sleep(1)
'''API语法:
获取⼿机⽹络driver.network_connection
设置⼿机⽹络driver.set_network_connection(connectionType)
⽹络类型有5种:
0(⽆):数据关闭、Wifi关闭、未开启⻜⾏模式
1(⻜⾏):数据关闭、Wifi关闭、开启⻜⾏模式
2(wifi):数据关闭、wifi打开、未开启⻜⾏模式
4(仅数据):数据开启、Wifi关闭、未开启⻜⾏模式
6(全部连接):数据开启、Wifi开启、未开启⻜⾏模式'''
print("当前手机网络类型:", driver.network_connection)
# 设置为飞行模式
driver.set_network_connection(1)
print("设置为飞行模式后手机网络类型:", driver.network_connection)
time.sleep(1)
# 设置为数据+wifi模式:6
driver.set_network_connection(6)
print("设置为数据+wifi模式后手机网络类型:", driver.network_connection)