def _get_info_for_first_matching_node(self, xpath):
        # type: (str) -> dict

        with self._get_node_ids(xpath) as node_ids:
            if node_ids:
                return self._describe_node(node_ids[0])
        raise ResourceNotFoundError("No matching nodes for xpath: %s" % xpath)
Example #2
0
 def execute(self, domain_name, method_name, params=None):
     result_id = self._execute(domain_name, method_name, params)
     result = self._wait_for_result(result_id)
     if "error" in result:
         code = result["error"]["code"]
         message = result["error"]["message"]
         if code == -32000:
             raise ResourceNotFoundError(message)
         if code == -32601:
             raise MethodNotFoundError(message)
         if code == -32602:
             raise InvalidParametersError(message)
         raise UnknownError("DevTools Protocol error code %s: %s" %
                            (code, message))
     return result
    def _get_iframe_backend_node_id(self, xpath):
        # type: (str) -> int

        if xpath in self._node_map:
            return self._node_map[xpath]

        node_info = self._get_info_for_first_matching_node(xpath)
        try:

            backend_node_id = node_info["node"]["contentDocument"][
                "backendNodeId"]
        except KeyError:
            raise ResourceNotFoundError(
                "The node found by xpath '%s' is not an iframe" % xpath)

        self._node_map[xpath] = backend_node_id
        return backend_node_id