MCPcopy
hub / github.com/AirtestProject/Poco / attr

Method attr

poco/proxy.py:701–741  ·  view source on GitHub ↗

Retrieve the attribute of UI element by given attribute name. Return None if attribute does not exist. If attribute type is :obj:`str`, it is encoded to utf-8 as :obj:`str` in Python2.7. Args: name: attribute name, it can be one of the following

(self, name)

Source from the content-addressed store, hash-verified

699
700 @refresh_when(PocoTargetRemovedException)
701 def attr(self, name):
702 """
703 Retrieve the attribute of UI element by given attribute name. Return None if attribute does not exist.
704 If attribute type is :obj:`str`, it is encoded to utf-8 as :obj:`str` in Python2.7.
705
706 Args:
707 name:
708 attribute name, it can be one of the following or any other customized type implemented by SDK
709
710 - visible: whether or not it is visible to user
711 - text: string value of the UI element
712 - type: the type name of UI element from remote runtime
713 - pos: the position of the UI element
714 - size: the percentage size [width, height] in range of 0~1 according to the screen
715 - name: the name of UI element
716 - ...: other sdk implemented attributes
717
718 Returns:
719 None if no such attribute or its value is None/null/nil/etc. Otherwise the attribute value is returned. The
720 returned value type is json serializable. In both py2 and py3, if the attribute value in remote is a
721 text-like object, the return value type will be :obj:`str`.
722
723 Raises:
724 PocoNoSuchNodeException: when the UI element does not exists
725
726 .. note:: Exception :py:class:`NodeHasBeenRemovedException` is caught automatically.
727
728 See Also:
729 :py:meth:`UI element attributes in poco sdk definition <poco.sdk.AbstractNode.AbstractNode.getAttr>`.
730 """
731
732 # to optimize performance speed, retrieve only the first matched element.
733 # 优化速度,只选择第一个匹配到的节点
734 nodes = self._do_query(multiple=False)
735 val = self.poco.agent.hierarchy.getAttr(nodes, name)
736 if six.PY2 and isinstance(val, six.text_type):
737 # 文本类型的属性值,只在python2里encode成utf-8的str,python3保持str类型
738 # 这是为了在写代码的时候,无论py2/3始终可以像下面这样写
739 # node.attr('text') == '节点属性值'
740 val = val.encode('utf-8')
741 return val
742
743 @refresh_when(PocoTargetRemovedException)
744 def setattr(self, name, val):

Callers 7

get_positionMethod · 0.95
existsMethod · 0.95
get_textMethod · 0.95
get_nameMethod · 0.95
get_sizeMethod · 0.95
runTestMethod · 0.80
test_instanceIdMethod · 0.80

Calls 2

_do_queryMethod · 0.95
getAttrMethod · 0.45

Tested by 1

test_instanceIdMethod · 0.64