折腾:
【未解决】iOS自动化处理WiFi代理:WiFi详情页中更新代理配置信息
期间,那为了测试能否点击 切换值,所以去故意改为1:
# for debug proxyConfigInfo = { 'type': '手动', 'value': { 'server': '192.168.31.46', 'port': '8081', # 'authenticate': '0' 'authenticate': '1' } }
去测试:
可以点击switch 切换值 是 选中状态了
继续调试
不过继续调试发现:
点击了 鉴定 后,右上角 存储 是灰色的,没法点击
[200615 09:51:17][DevicesMethods.py 856] Not found element {'type': 'XCUIElementTypeButton', 'name': '存储', 'enabled': 'true', 'parent_class_chains': ["/XCUIElementTypeNavigationBar[`name = '配置代理' AND rect.x = 0 AND rect.width = 414`]"]}
然后看到页面是:
感觉是:
必须输入用户名和密码,才能点击 存储?
看看xml
<XCUIElementTypeNavigationBar type="XCUIElementTypeNavigationBar" name="配置代理" enabled="true" visible="true" x="0" y="20" width="414" height="44"> <XCUIElementTypeButton type="XCUIElementTypeButton" name="xxx_guest_5G" label="xxx_guest_5G" enabled="true" visible="true" x="0" y="20" width="155" height="44"/> <XCUIElementTypeOther type="XCUIElementTypeOther" name="配置代理" label="配置代理" enabled="true" visible="true" x="172" y="31" width="70" height="21"/> <XCUIElementTypeButton type="XCUIElementTypeButton" name="存储" label="存储" enabled="false" visible="true" x="359" y="20" width="43" height="44"/> </XCUIElementTypeNavigationBar> <XCUIElementTypeTable type="XCUIElementTypeTable" enabled="true" visible="true" x="0" y="0" width="414" height="736"> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="99" width="414" height="45"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="99" width="414" height="1"/> <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="关闭" name="关闭" label="关闭" enabled="true" visible="true" x="20" y="99" width="374" height="45"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="143" width="394" height="1"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="144" width="414" height="45"> <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="手动" name="手动" label="手动" enabled="true" visible="true" x="20" y="144" width="350" height="45"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="188" width="394" height="1"/> <XCUIElementTypeButton type="XCUIElementTypeButton" name="更多信息" label="更多信息" enabled="false" visible="true" x="380" y="161" width="14" height="11"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="189" width="414" height="45"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="233" width="414" height="1"/> <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="自动" name="自动" label="自动" enabled="true" visible="true" x="20" y="189" width="374" height="45"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="269" width="414" height="46"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="269" width="414" height="1"/> <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="192.168.31.46" name="服务器" label="服务器" enabled="true" visible="true" x="92" y="281" width="294" height="21"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="313" width="305" height="1"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="313" width="394" height="2"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="314" width="414" height="46"> <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="8081" name="端口" label="端口" enabled="true" visible="true" x="74" y="326" width="312" height="22"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="358" width="305" height="2"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="359" width="394" height="1"/> </XCUIElementTypeCell> <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> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="404" width="414" height="46"> <XCUIElementTypeTextField type="XCUIElementTypeTextField" name="用户名" label="用户名" enabled="true" visible="true" x="92" y="416" width="294" height="22"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="448" width="305" height="2"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="449" width="394" height="1"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="449" width="414" height="47"> <XCUIElementTypeSecureTextField type="XCUIElementTypeSecureTextField" name="密码" label="密码" enabled="true" visible="true" x="74" y="461" width="312" height="22"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="494" width="414" height="2"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="493" width="305" height="2"/> </XCUIElementTypeCell> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="495" width="414" height="31"> <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="您的凭证可能以不加密方式发送" name="您的凭证可能以不加密方式发送" label="您的凭证可能以不加密方式发送" enabled="true" visible="true" x="0" y="495" width="414" height="31"/> </XCUIElementTypeOther> <XCUIElementTypeOther type="XCUIElementTypeOther" name="您的凭证可能以不加密方式发送" label="您的凭证可能以不加密方式发送" enabled="true" visible="false" x="0" y="495" width="414" height="31"/> </XCUIElementTypeTable>
下面是多出了几个选项:
用户名
密码
需要填写
此处还没输入,都是空,没有value值
所以要支持完整的代理配置,需要加上:
当 鉴定 = 1 时,额外要保存:用户名和密码的值
然后后续恢复时,也要恢复出来
去写代码
def getManualProxyValue(self, parentTableSoup): 。。。 authUser = None authPassword = None if proxyAuthenticate == "1": # need save user and password # <XCUIElementTypeTextField type="XCUIElementTypeTextField" name="用户名" label="用户名" enabled="true" visible="true" x="92" y="416" width="294" height="22"/> authUserSoup = parentTableSoup.find( 'XCUIElementTypeTextField', attrs={"type": "XCUIElementTypeTextField", "name": "用户名", "enabled":"true", "visible":"true"}, ) if not authUserSoup: return manualProxyValue authUser = authUserSoup.attrs.get("value", None) # 'xxx' # <XCUIElementTypeSecureTextField type="XCUIElementTypeSecureTextField" name="密码" label="密码" enabled="true" visible="true" x="74" y="461" width="312" height="22"/> authPasswordSoup = parentTableSoup.find( 'XCUIElementTypeTextField', attrs={"type": "XCUIElementTypeTextField", "name": "密码", "enabled":"true", "visible":"true"}, ) if not authPasswordSoup: return manualProxyValue authPassword = authPasswordSoup.attrs.get("value", None) # 'yyy' def setManualProxyValue(self, parentTableSoup, newManualProxyValue): 。。。 if newAuthenticateValue == "1": # need restore auth user and password newAuthUserValue = newManualProxyValue["authUser"] userFieldQuery = {"type":"XCUIElementTypeTextField", "name": "用户名", "enabled": "true"} userFieldQuery["parent_class_chains"] = [ parentCellClassChain ] isInputUserOk = self.wait_element_setText_iOS(userFieldQuery, newAuthUserValue) if not isInputUserOk: return False newAuthPasswordValue = newManualProxyValue["authPassword"] passwordFieldQuery = {"type":"XCUIElementTypeTextField", "name": "密码", "enabled": "true"} passwordFieldQuery["parent_class_chains"] = [ parentCellClassChain ] isInputPasswordOk = self.wait_element_setText_iOS(passwordFieldQuery, newAuthPasswordValue) if not isInputPasswordOk: return False
去调试看看
密码的text写错了,改为XCUIElementTypeSecureTextField:
authPasswordSoup = parentTableSoup.find( 'XCUIElementTypeSecureTextField', attrs={"type": "XCUIElementTypeSecureTextField", "name": "密码", "enabled":"true", "visible":"true"}, )
后续也改为:
passwordFieldQuery = {"type":"XCUIElementTypeSecureTextField", "name": "密码", "enabled": "true"}
继续:
此处调试,发现当前值是三个圆点,而不是我们希望的明文:
{'enabled': 'true', 'height': '22', 'label': '密码', 'name': '密码', 'type': 'XCUIElementTypeSecureTextField', 'value': '•••', 'visible': 'true', 'width': '312', 'x': '74', 'y': '461'}
获取出来的也是 三个黑点
-》无法获取到密码的值
再去看看此处xml是啥
xml
<XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="404" width="414" height="46"> <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="user" name="用户名" label="用户名" enabled="true" visible="true" x="92" y="416" width="294" height="22"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="448" width="305" height="2"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="449" width="394" height="1"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="449" width="414" height="47"> <XCUIElementTypeSecureTextField type="XCUIElementTypeSecureTextField" value="•••" name="密码" label="密码" enabled="true" visible="true" x="74" y="461" width="312" height="22"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="494" width="414" height="2"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="493" width="305" height="2"/> </XCUIElementTypeCell>
那此处,没办法了:
没法保存出 鉴定 时的 密码的明文
就没法完全恢复出密码的值
就不能支持 带 鉴定的密码值
除非自己代码中打印和警告,需要用户自己确保,恢复出来的密码值,是正确的。
authPassword = authPasswordSoup.attrs.get("value", None) # '•••' if '•' in authPassword: logging.warning("Get proxy autheticate password only get dot • -> Please user self makesure update the password is correct !")
继续。
[200615 10:30:06][DevicesMethods.py 2505] Get proxy autheticate password only get dot • -> Please user self makesure update the password is correct !
的确是包含的,所以提示了。
再去测试恢复:
# for debug # 'authUser': 'user', 'authPassword': '•••' proxyConfigInfo = { 'type': '手动', 'value': { 'server': '192.168.31.46', 'port': '8081', # 'authenticate': '0' 'authenticate': '1', 'authUser': 'user', 'authPassword': 'pwd', } }
即可。
【总结】
此处,对于开启了 认证 鉴定 后的 用户名 和 密码,分别去加上支持,相关代码是:
。。。 设置 无线局域网 配置代理 手动 开启 鉴定: <XCUIElementTypeTable type="XCUIElementTypeTable" enabled="true" visible="true" x="0" y="0" width="414" height="736"> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="99" width="414" height="45"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="99" width="414" height="1"/> <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="关闭" name="关闭" label="关闭" enabled="true" visible="true" x="20" y="99" width="374" height="45"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="143" width="394" height="1"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="144" width="414" height="45"> <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="手动" name="手动" label="手动" enabled="true" visible="true" x="20" y="144" width="350" height="45"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="188" width="394" height="1"/> <XCUIElementTypeButton type="XCUIElementTypeButton" name="更多信息" label="更多信息" enabled="false" visible="true" x="380" y="161" width="14" height="11"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="189" width="414" height="45"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="233" width="414" height="1"/> <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="自动" name="自动" label="自动" enabled="true" visible="true" x="20" y="189" width="374" height="45"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="269" width="414" height="46"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="269" width="414" height="1"/> <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="192.168.31.46" name="服务器" label="服务器" enabled="true" visible="true" x="92" y="281" width="294" height="21"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="313" width="305" height="1"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="313" width="394" height="2"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="314" width="414" height="46"> <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="8081" name="端口" label="端口" enabled="true" visible="true" x="74" y="326" width="312" height="22"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="358" width="305" height="2"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="359" width="394" height="1"/> </XCUIElementTypeCell> <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> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="404" width="414" height="46"> <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="user" name="用户名" label="用户名" enabled="true" visible="true" x="92" y="416" width="294" height="22"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="448" width="305" height="2"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="20" y="449" width="394" height="1"/> </XCUIElementTypeCell> <XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="449" width="414" height="47"> <XCUIElementTypeSecureTextField type="XCUIElementTypeSecureTextField" value="•••" name="密码" label="密码" enabled="true" visible="true" x="74" y="461" width="312" height="22"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="494" width="414" height="2"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="15" y="493" width="305" height="2"/> </XCUIElementTypeCell> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="495" width="414" height="31"> <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="您的凭证可能以不加密方式发送" name="您的凭证可能以不加密方式发送" label="您的凭证可能以不加密方式发送" enabled="true" visible="true" x="0" y="495" width="414" height="31"/> </XCUIElementTypeOther> <XCUIElementTypeOther type="XCUIElementTypeOther" name="您的凭证可能以不加密方式发送" label="您的凭证可能以不加密方式发送" enabled="true" visible="false" x="0" y="495" width="414" height="31"/> </XCUIElementTypeTable> 。。。 authUser = None authPassword = None if proxyAuthenticate == "1": # need save user and password # <XCUIElementTypeTextField type="XCUIElementTypeTextField" name="用户名" label="用户名" enabled="true" visible="true" x="92" y="416" width="294" height="22"/> authUserSoup = parentTableSoup.find( 'XCUIElementTypeTextField', attrs={"type": "XCUIElementTypeTextField", "name": "用户名", "enabled":"true", "visible":"true"}, ) if not authUserSoup: return manualProxyValue authUser = authUserSoup.attrs.get("value", None) # 'user' # <XCUIElementTypeSecureTextField type="XCUIElementTypeSecureTextField" name="密码" label="密码" enabled="true" visible="true" x="74" y="461" width="312" height="22"/> authPasswordSoup = parentTableSoup.find( 'XCUIElementTypeSecureTextField', attrs={"type": "XCUIElementTypeSecureTextField", "name": "密码", "enabled":"true", "visible":"true"}, ) if not authPasswordSoup: return manualProxyValue authPassword = authPasswordSoup.attrs.get("value", None) # '•••' if '•' in authPassword: logging.warning("Get proxy autheticate password only get dot • -> Please user self makesure the password is correct !") manualProxyValue = { "server": proxyServer, "port": proxyPort, "authenticate": proxyAuthenticate, "authUser": authUser, "authPassword": authPassword, } logging.info("manualProxyValue=%s", manualProxyValue) # manualProxyValue={'server': '192.168.31.46', 'port': '8081', 'authenticate': '0'} # manualProxyValue={'server': '192.168.31.46', 'port': '8081', 'authenticate': '1', 'authUser': 'user', 'authPassword': '•••'} return manualProxyValue def setManualProxyValue(self, parentTableSoup, newManualProxyValue): 。。。 if newAuthenticateValue == "1": # need restore auth user and password newAuthUserValue = newManualProxyValue["authUser"] userFieldQuery = {"type":"XCUIElementTypeTextField", "name": "用户名", "enabled": "true"} userFieldQuery["parent_class_chains"] = [ parentCellClassChain ] isInputUserOk = self.wait_element_setText_iOS(userFieldQuery, newAuthUserValue) if not isInputUserOk: return False newAuthPasswordValue = newManualProxyValue["authPassword"] passwordFieldQuery = {"type":"XCUIElementTypeSecureTextField", "name": "密码", "enabled": "true"} passwordFieldQuery["parent_class_chains"] = [ parentCellClassChain ] isInputPasswordOk = self.wait_element_setText_iOS(passwordFieldQuery, newAuthPasswordValue) if not isInputPasswordOk: return False
即可。