问题描述:
使用 Appium 框架测试 iOS APP ,该 APP 整个首页都是 H5,于是登陆进入 APP 后,我就开始打印 Contents,但是打印出来的只有 Native_APP,并没有 Web View 页面。

from appium import webdriver
import time
class Test01:
    server = 'http://localhost:4723/wd/hub'
    desired_caps = {'xcodeOrgId': "***********",
                    'xcodeSigningId': "iPhone Developer",
                    'udid': '**********',
                    'platformName': 'ios',
                    'platformVersion': '13.6.1',
                    'deviceName': 'iPhone7p',
                    'automationName': 'XCUITest',
                    'bundleId': '######',
                    "startIWDP": True
                    }
    driver = webdriver.Remote(server, desired_caps)

    def web_view(self):
        '''登陆按钮'''
    driver.find_element_by_xpath("//XCUIElementTypeButton[@name='登录']").click()
    '''账号输入框'''
    driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='******']"
                                                 "/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/"
                                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/"
                                                 "XCUIElementTypeOther/XCUIElementTypeTextField").click() #点击

    driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='*******']"
                                                 "/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/"
                                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/"
                                                 "XCUIElementTypeOther/XCUIElementTypeTextField").clear() #清空

    driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='*********']"
                                                 "/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/"
                                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/"
                                                 "XCUIElementTypeOther/XCUIElementTypeTextField").send_keys("19520518894") #输入账号
    ''''密码输入框'''
    driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='*******']"
                                             "/XCUIElementTypeWindow[1]/XCUIElementTypeOther/"
                                             "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/"
                                             "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeSecureTextField").click() #点击密码框

    driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='*******']"
                                 "/XCUIElementTypeWindow[1]/XCUIElementTypeOther/"
                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/"
                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeSecureTextField").clear() #清空

    driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='*******']"
                                 "/XCUIElementTypeWindow[1]/XCUIElementTypeOther/"
                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/"
                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeSecureTextField").send_keys("111111") #输入框

    driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='*******']"
                                 "/XCUIElementTypeWindow[1]/XCUIElementTypeOther/"
                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/"
                                 "XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeSecureTextField").send_keys("\n")  # 输入框

    driver.implicitly_wait(60)  # 隐式等待15秒
    for i in range(10):
        print(driver.contexts)
        time.sleep(1)

控制台打开的结果:

Appium 的打印日志如下:

[HTTP] <-- GET /wd/hub/session/cb549267-532f-487e-bb1b-ff576d39f680/contexts 200 6 ms - 24
[HTTP] 
[HTTP] --> GET /wd/hub/session/cb549267-532f-487e-bb1b-ff576d39f680/contexts
[HTTP] {}
[W3C (cb549267)] Calling AppiumDriver.getContexts() with args: ["cb549267-532f-487e-bb1b-ff576d39f680"]
[XCUITest] Executing command 'getContexts'
[XCUITest] Getting list of available contexts
[iOS] Retrieving contexts and views
[XCUITest] Selecting by url: false 
[RemoteDebugger] Sending connection key request
[RemoteDebugger] Sending '_rpc_reportIdentifier:' message (id: 10): 'setConnectionKey'
[RemoteDebugger] Sending to Web Inspector took 2ms
[RemoteDebugger] Selecting application
[RemoteDebugger] No applications currently connected.
[XCUITest] No web frames found.
[W3C (cb549267)] Responding to client with driver.getContexts() result: ["NATIVE_APP"]

有没有大佬能帮我看看,谢谢了


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