当Appium中遇到alert,可以使用switch_to_alert(),以下是微信登录切换登录方式的代码示例:
#coding=utf-8
from appium import webdriver
from time import sleep
import unittest class WxTestsCase(unittest.TestCase):
def setUp(self):
desired_cups={}
desired_cups['platformName']='Android'
desired_cups['platformVersion']='4.4.2'
desired_cups['deviceName']='DU2SSE15A9032675'
desired_cups['appPackage']='com.tencent.mm'
desired_cups['appActivity']='com.tencent.mm.ui.LauncherUI'
self.dr=webdriver.Remote("http://localhost:4725/wd/hub",desired_cups)
sleep(10)
def login(self):
self.dr.find_element_by_id('com.tencent.mm:id/ba_').click()
self.dr.switch_to_alert() #切换到alert窗口
self.dr.find_element_by_id('com.tencent.mm:id/et').click() #点击弹窗上的切换账号选项 if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(WxTestsCase('login'))
# suite.addTest(cleanTestsCase('youhua'))
# suite.addTest(cleanTestsCase('usual'))
unittest.TextTestRunner(verbosity=2).run(suite)
#coding=utf-8
from appium import webdriver
from time import sleep
import unittest class WxTestsCase(unittest.TestCase):
def setUp(self):
desired_cups={}
desired_cups['platformName']='Android'
desired_cups['platformVersion']='4.4.2'
desired_cups['deviceName']='DU2SSE15A9032675'
desired_cups['appPackage']='com.tencent.mm'
desired_cups['appActivity']='com.tencent.mm.ui.LauncherUI'
self.dr=webdriver.Remote("http://localhost:4725/wd/hub",desired_cups)
sleep(10)
def login(self):
self.dr.find_element_by_id('com.tencent.mm:id/ba_').click()
self.dr.switch_to_alert() #切换到alert窗口
self.dr.find_element_by_id('com.tencent.mm:id/et').click() #点击弹窗上的切换账号选项 if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(WxTestsCase('login'))
# suite.addTest(cleanTestsCase('youhua'))
# suite.addTest(cleanTestsCase('usual'))
unittest.TextTestRunner(verbosity=2).run(suite)