最新消息:20210917 已从crifan.com换到crifan.org

【已解决】iPhone中切换AppStore到搜索tab输入app名字并搜索

切换 crifan 177浏览 0评论
折腾:
【未解决】iOS自动化:通过AppStore自动下载和安装iOS的app京东
期间,先去实现
启动AppStore
切换到搜索的tab页
输入app的名字
再点击搜索按钮触发搜索-》期望:进入搜索列表页
重启AppStore后仍然默认进去搜索页
不过为了保险,还是主动找到并点击切换到搜索的tab
xml
<XCUIElementTypeTabBar type="XCUIElementTypeTabBar" enabled="true" visible="true" x="0" y="687" width="414" height="49">
    <XCUIElementTypeButton type="XCUIElementTypeButton" name="Today" label="Today" enabled="true" visible="true" x="2" y="688" width="80" height="48"/>
    <XCUIElementTypeButton type="XCUIElementTypeButton" name="游戏" label="游戏" enabled="true" visible="true" x="85" y="688" width="80" height="48"/>
    <XCUIElementTypeButton type="XCUIElementTypeButton" name="App" label="App" enabled="true" visible="true" x="168" y="688" width="78" height="48"/>
    <XCUIElementTypeButton type="XCUIElementTypeButton" name="更新" label="更新" enabled="true" visible="true" x="249" y="688" width="80" height="48"/>
    <XCUIElementTypeButton type="XCUIElementTypeButton" value="1" name="搜索" label="搜索" enabled="true" visible="true" x="332" y="688" width="80" height="48"/>
</XCUIElementTypeTabBar>
去写代码,定位到 搜索tab
用代码:
        isSwitchOk = self.switchToAppStoreSearchTab()
    
    def switchToAppStoreSearchTab(self):
        """try find and click to switch to AppStore search tab"""
        isSwitchOk = False
        """
            AppStore 底部tab:
                <XCUIElementTypeTabBar type="XCUIElementTypeTabBar" enabled="true" visible="true" x="0" y="687" width="414" height="49">
                    <XCUIElementTypeButton type="XCUIElementTypeButton" name="Today" label="Today" enabled="true" visible="true" x="2" y="688" width="80" height="48"/>
                    <XCUIElementTypeButton type="XCUIElementTypeButton" name="游戏" label="游戏" enabled="true" visible="true" x="85" y="688" width="80" height="48"/>
                    <XCUIElementTypeButton type="XCUIElementTypeButton" name="App" label="App" enabled="true" visible="true" x="168" y="688" width="78" height="48"/>
                    <XCUIElementTypeButton type="XCUIElementTypeButton" name="更新" label="更新" enabled="true" visible="true" x="249" y="688" width="80" height="48"/>
                    <XCUIElementTypeButton type="XCUIElementTypeButton" value="1" name="搜索" label="搜索" enabled="true" visible="true" x="332" y="688" width="80" height="48"/>
                </XCUIElementTypeTabBar>
        """
        parentTabBarClassChain = "/XCUIElementTypeTabBar[`rect.x = 0 AND rect.width = %d`]" % self.X
        searchButtonQuery = {"type":"XCUIElementTypeButton", "name": "搜索", "label": "搜索", "enabled": "true"}
        searchButtonQuery["parent_class_chains"] = [ parentTabBarClassChain ]
        foundAndClicked = self.findAndClickElement(query=searchButtonQuery, timeout=0.2)
        isSwitchOk = foundAndClicked
        return isSwitchOk
调试,可以找到并点击:
继续
        if isSwitchOk:
            """
                <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="116" width="414" height="52">
                    <XCUIElementTypeSearchField type="XCUIElementTypeSearchField" name="App Store" label="App Store" enabled="true" visible="true" x="20" y="117" width="374" height="36"/>
                </XCUIElementTypeOther>
            """
            searchInputQuery = {"type":"XCUIElementTypeSearchField", "name":"App Store"}
            isInputOk = self.wait_element_setText(searchInputQuery, appName)
可以找到并输入:京东
xml
<XCUIElementTypeButton type="XCUIElementTypeButton" name="Search" label="搜索" enabled="true" visible="true" x="309" y="685" width="103" height="50"/>
而此处之前已有相关search代码,略作优化后:
src/common/DevicesMethods.py
    def search_iOS(self, wait=1):
        # 触发点击搜索按钮
        foundAndClickedDoSearch = False
        # <XCUIElementTypeButton type="XCUIElementTypeButton" name="Search" label="Search" enabled="true" visible="true" x="281" y="620" width="94" height="47"/>
        # <XCUIElementTypeButton type="XCUIElementTypeButton" name="Search" label="搜索" enabled="true" visible="true" x="309" y="685" width="103" height="50"/>
        # searchButtonQuery = {"name": "Search"}
        searchButtonQuery = {"name": "Search", "type": "XCUIElementTypeButton"}
        # Note: occasionally not found Search, change to find multiple time to avoid this kind of case
        MaxRetryNumber = 5
        curRetryNumber = MaxRetryNumber
        while curRetryNumber > 0:
            foundAndClickedDoSearch = self.findAndClickElement(searchButtonQuery, timeout=wait)
            if foundAndClickedDoSearch:
                break
        
            curRetryNumber -= 1


        if not foundAndClickedDoSearch:
            logging.error("Not found and/or clicked for %s", searchButtonQuery)
        return foundAndClickedDoSearch
去调试看看,是可以的。
接着去:
【已解决】AppStore自动安装iOS的app京东:支持搜索结果列表页
【后记20200611】
折腾:
【未解决】iOS自动处理WiFi代理:配置代理页中从手动切换到关闭且保留之前代理配置信息
期间,遇到了,之前就猜测会发生的:
AppStore启动后,默认进去的tab,不是搜索,而是 第一个 Today
-》证明了之前的 启动AppStore后,加上代码,跳转到 搜索页,是明智的选择。

转载请注明:在路上 » 【已解决】iPhone中切换AppStore到搜索tab输入app名字并搜索

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.111 seconds, using 21.62MB memory