新手,不知道为什么切换 WEBVIEW 的时候,老是报错。
日志如下:

info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.paic.ibankadnroidsmp
info: [debug] ["WEBVIEW_com.paic.ibankadnroidsmp"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.paic.ibankadnroidsmp
info: [debug] Connecting to chrome-backed webview
info: Set chromedriver binary as: F:\mysoft\Appium1.4\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"9515 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %a))
info: No old chromedrivers seemed to exist
info: Spawning chromedriver with: F:\mysoft\Appium1.4\node_modules\appium\build\chromedriver\windows\chromedriver.exe --url-base=wd/hub --port=9515
info: [CHROMEDRIVER STDOUT] Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515
Only local connections are allowed.
info: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
info: Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Windows NT","version":"6.3"}}}
info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.paic.ibankadnroidsmp","androidUseRunningApp":true,"androidDeviceSerial":"NX511J"}}}
info: Got response with status 200: {"sessionId":"b87040b60891df760f1c109d27a2c150","status":13,"value":{"message":"unknown error: Device NX511J is not online\n (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a203268398...
info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.paic.ibankadnroidsmp","androidUseRunningApp":true,"androidDeviceSerial":"NX511J"}}}
info: Got response with status 200: {"sessionId":"63960ff2cde290f6daa6f6fe77ee078e","status":13,"value":{"message":"unknown error: Device NX511J is not online\n (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a203268398...
info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.paic.ibankadnroidsmp","androidUseRunningApp":true,"androidDeviceSerial":"NX511J"}}}
info: Got response with status 200: {"sessionId":"4c9314129cb798504e88618de9cfaf04","status":13,"value":{"message":"unknown error: Device NX511J is not online\n (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a203268398...
info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.paic.ibankadnroidsmp","androidUseRunningApp":true,"androidDeviceSerial":"NX511J"}}}
info: Got response with status 200: {"sessionId":"aed9c4de7077e75f28fb04e51503512f","status":13,"value":{"message":"unknown error: Device NX511J is not online\n (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a203268398...

部分代码如下:

def test_ibank(self):

    logging.info('程序启动中,请稍等……')
    #time.sleep(20)    
    #logging.FileHandler('e:/auto_test_log.log')
    start = time.clock()
    #等待程序启动
    while True:
        try:
            #查找登陆按钮 ,以找到登陆按钮提示启动成功
            el = self.driver.find_element_by_id("com.paic.ibankadnroidsmp:id/top_right_tx") 
        except Exception:
            continue
        else:
            end = time.clock()
            logging.info('程序启动成功')
            #输出启动耗时
            logging.info('程序启动用时: %f s'%(end-start))
            break

    logging.info('点击登陆按钮')        
    el.click()    
    time.sleep(2)
    context=self.driver.contexts
    self.assertEqual(2, len(context))
    time.sleep(5)
    self.driver.switch_to.context('WEBVIEW')
    time.sleep(1)
    el=self.driver.find_element_by_id('userName')
    #el.click
    el.send_keys('username')
    js_password="$(\"#login_password\").customInput(\'setValue\',\'password\')"
    try:
        self.driver.execute_script(js_password)
    except Exception as e:
        logging.info('JS脚本执行错误,错误:%s'%e)

但是我用 ADB 的时候,真机是可以找到的!!!而且有时候能过,有时候不能过!!有么有 人知道,求高手。真心感谢!!


↙↙↙阅读原文可查看相关链接,并与作者交流