本文整理汇总了Python中errorhandler.ErrorHandler.check_response方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorHandler.check_response方法的具体用法?Python ErrorHandler.check_response怎么用?Python ErrorHandler.check_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类errorhandler.ErrorHandler
的用法示例。
在下文中一共展示了ErrorHandler.check_response方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WebDriver
# 需要导入模块: from errorhandler import ErrorHandler [as 别名]
# 或者: from errorhandler.ErrorHandler import check_response [as 别名]
#.........这里部分代码省略.........
def create_web_element(self, element_id):
"""
Creates a web element with the specified element_id.
"""
return WebElement(self, element_id)
def _unwrap_value(self, value):
if isinstance(value, dict) and 'ELEMENT' in value:
return self.create_web_element(value['ELEMENT'])
elif isinstance(value, list):
return list(self._unwrap_value(item) for item in value)
else:
return value
def execute(self, driver_command, params=None):
"""
Sends a command to be executed by a command.CommandExecutor.
:Args:
- driver_command: The name of the command to execute as a string.
- params: A dictionary of named parameters to send with the command.
:Returns:
The command's JSON response loaded into a dictionary object.
"""
if not params:
params = {'sessionId': self.session_id}
elif 'sessionId' not in params:
params['sessionId'] = self.session_id
params = self._wrap_value(params)
response = self.command_executor.execute(driver_command, params)
if response:
self.error_handler.check_response(response)
response['value'] = self._unwrap_value(
response.get('value', None))
return response
# If the server doesn't send a response, assume the command was
# a success
return {'success': 0, 'value': None, 'sessionId': self.session_id}
def get(self, url):
"""
Loads a web page in the current browser session.
"""
self.execute(Command.GET, {'url': url})
@property
def title(self):
"""Returns the title of the current page.
:Usage:
driver.title
"""
resp = self.execute(Command.GET_TITLE)
return resp['value'] if resp['value'] is not None else ""
def find_element_by_id(self, id_):
"""Finds an element by id.
:Args:
- id\_ - The id of the element to be found.
:Usage:
driver.find_element_by_id('foo')
"""
示例2: WebDriver
# 需要导入模块: from errorhandler import ErrorHandler [as 别名]
# 或者: from errorhandler.ErrorHandler import check_response [as 别名]
#.........这里部分代码省略.........
return list(self._wrap_value(item) for item in value)
else:
return value
def create_web_element(self, element_id):
return WebElement(self, element_id)
def _unwrap_value(self, value):
if isinstance(value, dict) and 'ELEMENT' in value:
return self.create_web_element(value['ELEMENT'])
elif isinstance(value, list):
return list(self._unwrap_value(item) for item in value)
else:
return value
def execute(self, driver_command, params=None):
"""Sends a command to be executed by a command.CommandExecutor.
Args:
driver_command: The name of the command to execute as a string.
params: A dictionary of named parameters to send with the command.
Returns:
The command's JSON response loaded into a dictionary object.
"""
if not params:
params = {'sessionId': self.session_id}
elif 'sessionId' not in params:
params['sessionId'] = self.session_id
params = self._wrap_value(params)
response = self.command_executor.execute(driver_command, params)
if response:
self.error_handler.check_response(response)
response['value'] = self._unwrap_value(
response.get('value', None))
return response
# If the server doesn't send a response, assume the command was
# a success
return {'success': 0, 'value': None}
def get(self, url):
"""Loads a web page in the current browser."""
self.execute(Command.GET, {'url': url})
@property
def title(self):
"""Gets the title of the current page."""
resp = self.execute(Command.GET_TITLE)
return resp['value'] if resp['value'] is not None else ""
def find_element_by_id(self, id_):
"""Finds element by id."""
return self.find_element(by=By.ID, value=id_)
def find_elements_by_id(self, id_):
"""Finds element by id."""
return self.find_elements(by=By.ID, value=id_)
def find_elements_by_xpath(self, xpath):
"""Finds multiple elements by xpath."""
return self.find_elements(by=By.XPATH, value=xpath)
def find_element_by_xpath(self, xpath):
"""Finds an element by xpath."""
return self.find_element(by=By.XPATH, value=xpath)
示例3: WebDriver
# 需要导入模块: from errorhandler import ErrorHandler [as 别名]
# 或者: from errorhandler.ErrorHandler import check_response [as 别名]
#.........这里部分代码省略.........
elif isinstance(value, list):
return list(self._wrap_value(item) for item in value)
else:
return value
def create_web_element(self, element_id):
"""Creates a web element with the specified element_id."""
return WebElement(self, element_id)
def _unwrap_value(self, value):
if isinstance(value, dict) and "ELEMENT" in value:
return self.create_web_element(value["ELEMENT"])
elif isinstance(value, list):
return list(self._unwrap_value(item) for item in value)
else:
return value
def execute(self, driver_command, params=None):
"""Sends a command to be executed by a command.CommandExecutor.
Args:
driver_command: The name of the command to execute as a string.
params: A dictionary of named parameters to send with the command.
Returns:
The command's JSON response loaded into a dictionary object.
"""
if not params:
params = {"sessionId": self.session_id}
elif "sessionId" not in params:
params["sessionId"] = self.session_id
params = self._wrap_value(params)
response = self.command_executor.execute(driver_command, params)
if response:
self.error_handler.check_response(response)
response["value"] = self._unwrap_value(response.get("value", None))
return response
# If the server doesn't send a response, assume the command was
# a success
return {"success": 0, "value": None}
def get(self, url):
"""Loads a web page in the current browser session."""
self.execute(Command.GET, {"url": url})
@property
def title(self):
"""Returns the title of the current page.
Usage:
driver.title
"""
resp = self.execute(Command.GET_TITLE)
return resp["value"] if resp["value"] is not None else ""
def find_element_by_id(self, id_):
"""Finds an element by id.
Args:
id_: The id of the element to be found.
Usage:
driver.find_element_by_id('foo')
"""
return self.find_element(by=By.ID, value=id_)
def find_elements_by_id(self, id_):
"""Finds multiple elements by id.
Args:
id_: The id of the elements to be found.
示例4: WebDriver
# 需要导入模块: from errorhandler import ErrorHandler [as 别名]
# 或者: from errorhandler.ErrorHandler import check_response [as 别名]
#.........这里部分代码省略.........
return list(self._wrap_value(item) for item in value)
else:
return value
def create_web_element(self, element_id):
return WebElement(self, element_id)
def _unwrap_value(self, value):
if isinstance(value, dict) and 'ELEMENT' in value:
return self.create_web_element(value['ELEMENT'])
elif isinstance(value, list):
return list(self._unwrap_value(item) for item in value)
else:
return value
def _execute(self, driver_command, params=None):
"""Sends a command to be executed by a command.CommandExecutor.
Args:
driver_command: The name of the command to execute as a string.
params: A dictionary of named parameters to send with the command.
Returns:
The command's JSON response loaded into a dictionary object.
"""
if not params:
params = {'sessionId': self.session_id}
elif 'sessionId' not in params:
params['sessionId'] = self.session_id
params = self._wrap_value(params)
response = self.command_executor.execute(driver_command, params)
if response:
self.error_handler.check_response(response)
response['value'] = self._unwrap_value(
response.get('value', None))
return response
# If the server doesn't send a response, assume the command was
# a success
return {'success': 0, 'value': None}
def get(self, url):
"""Loads a web page in the current browser."""
self._execute(Command.GET, {'url': url})
def get_title(self):
"""Gets the title of the current page."""
resp = self._execute(Command.GET_TITLE)
return resp['value']
def find_element_by_id(self, id_):
"""Finds element by id."""
return self._find_element_by("id", id_)
def find_elements_by_xpath(self, xpath):
"""Finds multiple elements by xpath."""
return self._find_elements_by("xpath", xpath)
def find_element_by_xpath(self, xpath):
"""Finds an element by xpath."""
return self._find_element_by("xpath", xpath)
def find_element_by_link_text(self, link_text):
"""Finds an element by its link text."""
return self._find_element_by("link text", link_text)
示例5: WebDriver
# 需要导入模块: from errorhandler import ErrorHandler [as 别名]
# 或者: from errorhandler.ErrorHandler import check_response [as 别名]
#.........这里部分代码省略.........
return list(self._wrap_value(item) for item in value)
else:
return value
def create_web_element(self, element_id):
return WebElement(self, element_id)
def _unwrap_value(self, value):
if isinstance(value, dict) and "ELEMENT" in value:
return self.create_web_element(value["ELEMENT"])
elif isinstance(value, list):
return list(self._unwrap_value(item) for item in value)
else:
return value
def execute(self, driver_command, params=None):
"""Sends a command to be executed by a command.CommandExecutor.
Args:
driver_command: The name of the command to execute as a string.
params: A dictionary of named parameters to send with the command.
Returns:
The command's JSON response loaded into a dictionary object.
"""
if not params:
params = {"sessionId": self.session_id}
elif "sessionId" not in params:
params["sessionId"] = self.session_id
params = self._wrap_value(params)
response = self.command_executor.execute(driver_command, params)
if response:
self.error_handler.check_response(response)
response["value"] = self._unwrap_value(response.get("value", None))
return response
# If the server doesn't send a response, assume the command was
# a success
return {"success": 0, "value": None}
def get(self, url):
"""Loads a web page in the current browser."""
self.execute(Command.GET, {"url": url})
@property
def title(self):
"""Gets the title of the current page."""
resp = self.execute(Command.GET_TITLE)
return resp["value"] if resp["value"] is not None else ""
def find_element_by_id(self, id_):
"""Finds element by id."""
return self.find_element(by=By.ID, value=id_)
def find_elements_by_id(self, id_):
"""Finds element by id."""
return self.find_elements(by=By.ID, value=id_)
def find_elements_by_xpath(self, xpath):
"""Finds multiple elements by xpath."""
return self.find_elements(by=By.XPATH, value=xpath)
def find_element_by_xpath(self, xpath):
"""Finds an element by xpath."""
return self.find_element(by=By.XPATH, value=xpath)