poco.sdk.Selector module

class ISelector[source]

Bases: object

This interface defines the standard selector behavior. Selector is used for selecting the specific UI element(s) by given query expression (formal definitions are in specific implementation classes).

select(cond, multiple=False)[source]
Parameters:
  • cond (tuple) – query expressiom

  • multiple (bool) – whether or not to select the multiple elements. If set to True, the method terminates immediately once the node is found, otherwise it traverses through all nodes and then exists

Returns:

list <inherited from AbstractNode>

Return type:

list

class Selector(dumper, matcher=None)[source]

Bases: ISelector

This class implements the standard Selector interface that uses DFS algorithm to travers through tree-like hierarchy structure. It supports flexible query expressions such as parental relationship, attribute predicate, etc. Any combinations of expressions mentioned above are also allowed as the query conditions.

The query expression can be defined as follows:

expr := (op0, (expr0, expr1))
expr := ('index', (expr, :obj:`int`))
expr := <other query condition> See implementation of Matcher.
  • op0 can be one of the following (‘>’, ‘/’, ‘-‘), each operator stands for as follows:

    '>': offsprings, select all offsprings matched expr1 from all roots matched expr0.
    '/': children, select all children matched expr1 from all roots matched expr0.
    '-': siblings, select all siblings matched expr1 from all roots matched expr0.
    '^': parent, select the parent of 1st UI element matched expr0. expr1 is always None.
    
  • 'index': select specific n-th UI element from the previous results

  • others: passes the expression to matcher

Parameters:
  • dumper (any implementation of IDumper) – dumper for the selector

  • matcher (any implementation of IMatcher) – DefaultMatcher instance by default.

getRoot()[source]

Get a default root node.

Returns:

default root node from the dumper.

select(cond, multiple=False)[source]

See Also: select method in ISelector.

selectImpl(cond, multiple, root, maxDepth, onlyVisibleNode, includeRoot)[source]

Selector internal implementation. TODO: add later.

Note

This doc shows only the outline of the algorithm. Do not call this method in your code as this is an internal method.

Parameters:
  • cond (tuple) – query expression

  • multiple (bool) – whether or not to select multiple nodes. If true, all nodes that matches the given condition will return, otherwise, only the first node matches will.

  • root (inherited from AbstractNode) – start traversing from the given root node

  • maxDepth (bool) – max traversing depth

  • onlyVisibleNode (bool) – If True, skip those node which visibility (the value of visible attribute) is False.

  • includeRoot (bool) – whether not not to include the root node if its child(ren) match(es) the node

Returns:

The same as

select.

Return type:

list <inherited from AbstractNode>