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

【已解决】facebook-wda获取鉴定的value值是错误的

获取 crifan 346浏览 0评论
折腾:
【未解决】iOS自动化处理WiFi代理:WiFi详情页中更新代理配置信息
期间,界面中:
在清除了旧的 服务器 和端口,分别输入了新的值后
去处理 鉴定
找到了鉴定 元素,但是获取值,竟然是 0:
不是希望的 实际的值 1
导致后续逻辑异常,没有去点击switch
那这个恶心的bug,真的是没法规避了。。。
不过注意到:
                    <XCUIElementTypeCell type="XCUIElementTypeCell" value="1" enabled="true" visible="true" x="0" y="359" width="414" height="46">
                      <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="鉴定" name="鉴定" label="鉴定" enabled="true" visible="true" x="20" y="359" width="323" height="46"/>
                      <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="404" width="394" height="1"/>
                      <XCUIElementTypeSwitch type="XCUIElementTypeSwitch" value="1" name="鉴定" label="鉴定" enabled="true" visible="true" x="343" y="366" width="51" height="32"/>
                    </XCUIElementTypeCell>
即,xml中源码的值,倒是准的,是1
-》可以考虑换用bs的find
-》虽然慢点,但是至少值是准的

        curAuthValueStr = ""
        # curAuthValue = authSwitchElement.value # '0'
        # curAuthValueStr = str(curAuthValue)
        # Special: sometime wda element value is WRONG, actual is '1', but got '0'
        # so change to bs find then get value from page source xml
        curPageXml = self.get_page_source()
        soup = CommonUtils.xmlToSoup(curPageXml)
        authSwitchChainList = [
            {
                "tag": "XCUIElementTypeTable",
                "attrs": self.FullScreenAttrDict
            },
            {
                "tag": "XCUIElementTypeCell",
                "attrs": {"enabled":"true", "visible":"true", "x":"0", "width":"%s" % self.X}
            },
            {
                "tag": "XCUIElementTypeSwitch",
                "attrs": {"enabled":"true", "visible":"true", "name": "鉴定"}
            },
        ]
        authSwitchSoup = CommonUtils.bsChainFind(soup, authSwitchChainList)
        if authSwitchSoup:
            curAuthValue =  authSwitchSoup.attrs.get("value", None)
            if curAuthValue:
                curAuthValueStr = str(curAuthValue)
        
        if curAuthValueStr == "":
            return False
去调试
可以获取到正确的值 1
与之相对,element的value是错误的:0
【总结】
此处,页面上是:
但是,对于 鉴定,用wda的query找到了元素,其value值,是错误的:0
而不是实际上的值:1
最后改用获取xml源码,其中值是正确的1,再去bs的find找到元素,即可获取正确的值

        """
                    <XCUIElementTypeCell type="XCUIElementTypeCell" value="0" enabled="true" visible="true" x="0" y="359" width="414" height="46">
                        <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="404" width="414" height="1"/>
                        <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="鉴定" name="鉴定" label="鉴定" enabled="true" visible="true" x="20" y="359" width="323" height="46"/>
                        <XCUIElementTypeSwitch type="XCUIElementTypeSwitch" value="0" name="鉴定" label="鉴定" enabled="true" visible="true" x="343" y="366" width="51" height="32"/>
                    </XCUIElementTypeCell>
        """
        newAuthenticateValue = newManualProxyValue["authenticate"]
        authSwitchQuery = {"type":"XCUIElementTypeSwitch", "name": "鉴定", "enabled": "true"}
        authSwitchQuery["parent_class_chains"] = [ parentCellClassChain ]
        foundAuth, respInfo = self.findElement(authSwitchQuery, timeout=0.1)
        if not foundAuth:
            return False


        authSwitchElement = respInfo


        curAuthValueStr = ""
        # curAuthValue = authSwitchElement.value # '0'
        # curAuthValueStr = str(curAuthValue)
        # Special: sometime wda element value is WRONG, actual is '1', but got '0'
        # so change to bs find then get value from page source xml
        curPageXml = self.get_page_source()
        soup = CommonUtils.xmlToSoup(curPageXml)
        authSwitchChainList = [
            {
                "tag": "XCUIElementTypeTable",
                "attrs": self.FullScreenAttrDict
            },
            {
                "tag": "XCUIElementTypeCell",
                "attrs": {"enabled":"true", "visible":"true", "x":"0", "width":"%s" % self.X}
            },
            {
                "tag": "XCUIElementTypeSwitch",
                "attrs": {"enabled":"true", "visible":"true", "name": "鉴定"}
            },
        ]
        authSwitchSoup = CommonUtils.bsChainFind(soup, authSwitchChainList)
        if authSwitchSoup:
            curAuthValue =  authSwitchSoup.attrs.get("value", None)
            if curAuthValue:
                curAuthValueStr = str(curAuthValue)
        
        if curAuthValueStr == "":
            return False


        if curAuthValueStr != newAuthenticateValue:
            # click switch element to change value
            isClickOk = self.clickElement(authSwitchElement)
            if not isClickOk:
                return False
即可。

转载请注明:在路上 » 【已解决】facebook-wda获取鉴定的value值是错误的

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.181 seconds, using 23.26MB memory