def send_command(self, method, uri, body=None): """ Send a command to the remote end and validate its success. :param method: HTTP method to use in request. :param uri: "Command part" of the HTTP request URL, e.g. `window/rect`. :param body: Optional body of the HTTP request. :return: `None` if the HTTP response body was empty, otherwise the result of parsing the body as JSON. :raises error.SessionNotCreatedException: If there is no active session. :raises error.WebDriverException: If the remote end returns an error. """ if self.session_id is None: raise error.SessionNotCreatedException() url = urlparse.urljoin("session/%s/" % self.session_id, uri) response = self.send_raw_command(method, url, body) rv = response.body["value"] if not rv: rv = None return rv
def send_command(self, method, url, body=None, key=None): """Send a command to the remote end and validate its success. :param method: HTTP method to use in request :param url: "command part" of the requests URL path :param body: body of the HTTP request :param key: (deprecated) when specified, this string value will be used to de-reference the HTTP response body following JSON parsing :return: None if the HTTP response body was empty, otherwise the result of parsing the HTTP response body as JSON """ if self.session_id is None: raise error.SessionNotCreatedException() response = self.send_raw_command(method, url, body) if response.status != 200: cls = error.get(response.body["value"].get("error")) raise cls(response.body["value"].get("message")) if key is not None: response.body = response.body[key] if not response.body: response.body = None return response.body
def send_command(self, method, url, body=None, key=None): if self.session_id is None: raise error.SessionNotCreatedException() url = urlparse.urljoin("session/%s/" % self.session_id, url) return self.transport.send(method, url, body, key=key)