mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
修改报错提示
This commit is contained in:
parent
a5f90f5dd9
commit
95287fd8a9
@ -69,7 +69,7 @@ class Drission(object):
|
|||||||
if isinstance(self._driver_options, dict):
|
if isinstance(self._driver_options, dict):
|
||||||
options = _dict_to_chrome_options(self._driver_options)
|
options = _dict_to_chrome_options(self._driver_options)
|
||||||
else:
|
else:
|
||||||
raise KeyError('Driver options invalid')
|
raise TypeError('Driver options invalid')
|
||||||
|
|
||||||
if self._proxy:
|
if self._proxy:
|
||||||
options.add_argument(f'--proxy-server={self._proxy["http"]}')
|
options.add_argument(f'--proxy-server={self._proxy["http"]}')
|
||||||
|
@ -122,7 +122,7 @@ class DriverElement(DrissionElement):
|
|||||||
elif isinstance(loc_or_str, tuple) and len(loc_or_str) == 2:
|
elif isinstance(loc_or_str, tuple) and len(loc_or_str) == 2:
|
||||||
loc_or_str = translate_loc_to_xpath(loc_or_str)
|
loc_or_str = translate_loc_to_xpath(loc_or_str)
|
||||||
else:
|
else:
|
||||||
raise ValueError('loc_or_str must be tuple or str.')
|
raise ValueError('Argument loc_or_str can only be tuple or str.')
|
||||||
|
|
||||||
if loc_or_str[0] == 'xpath':
|
if loc_or_str[0] == 'xpath':
|
||||||
# 确保查询语句最前面是.
|
# 确保查询语句最前面是.
|
||||||
@ -162,8 +162,9 @@ class DriverElement(DrissionElement):
|
|||||||
self.clear()
|
self.clear()
|
||||||
self.inner_ele.send_keys(value)
|
self.inner_ele.send_keys(value)
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception as e:
|
||||||
raise
|
print(e)
|
||||||
|
return False
|
||||||
|
|
||||||
def run_script(self, script: str) -> Any:
|
def run_script(self, script: str) -> Any:
|
||||||
"""运行js"""
|
"""运行js"""
|
||||||
@ -237,8 +238,9 @@ class DriverElement(DrissionElement):
|
|||||||
try:
|
try:
|
||||||
self.run_script(f"arguments[0].{attr} = '{value}';")
|
self.run_script(f"arguments[0].{attr} = '{value}';")
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception as e:
|
||||||
raise
|
print(e)
|
||||||
|
return False
|
||||||
|
|
||||||
def drag(self, x: int, y: int, speed: int = 40, shake: bool = True) -> bool:
|
def drag(self, x: int, y: int, speed: int = 40, shake: bool = True) -> bool:
|
||||||
"""拖拽当前元素到相对位置
|
"""拖拽当前元素到相对位置
|
||||||
@ -269,7 +271,7 @@ class DriverElement(DrissionElement):
|
|||||||
elif isinstance(ele_or_loc, tuple):
|
elif isinstance(ele_or_loc, tuple):
|
||||||
target_x, target_y = ele_or_loc
|
target_x, target_y = ele_or_loc
|
||||||
else:
|
else:
|
||||||
raise KeyError('Need DriverElement, WebElement object or coordinate information.')
|
raise TypeError('Need DriverElement, WebElement object or coordinate information.')
|
||||||
|
|
||||||
current_x = self.location['x'] + self.size['width'] // 2
|
current_x = self.location['x'] + self.size['width'] // 2
|
||||||
current_y = self.location['y'] + self.size['height'] // 2
|
current_y = self.location['y'] + self.size['height'] // 2
|
||||||
@ -317,7 +319,7 @@ def execute_driver_find(page_or_ele: Union[WebElement, WebDriver],
|
|||||||
"""
|
"""
|
||||||
mode = mode or 'single'
|
mode = mode or 'single'
|
||||||
if mode not in ['single', 'all']:
|
if mode not in ['single', 'all']:
|
||||||
raise ValueError("mode must be 'single' or 'all'.")
|
raise ValueError("Argument mode can only be 'single' or 'all'.")
|
||||||
msg = result = None
|
msg = result = None
|
||||||
try:
|
try:
|
||||||
wait = WebDriverWait(page_or_ele, timeout=timeout)
|
wait = WebDriverWait(page_or_ele, timeout=timeout)
|
||||||
|
@ -106,7 +106,7 @@ class DriverPage(object):
|
|||||||
:return: 等待是否成功
|
:return: 等待是否成功
|
||||||
"""
|
"""
|
||||||
if mode.lower() not in ['del', 'display', 'hidden']:
|
if mode.lower() not in ['del', 'display', 'hidden']:
|
||||||
raise ValueError('mode can only be "del", "display", "hidden"')
|
raise ValueError('Argument mode can only be "del", "display", "hidden"')
|
||||||
|
|
||||||
from selenium.webdriver.support.wait import WebDriverWait
|
from selenium.webdriver.support.wait import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as ec
|
from selenium.webdriver.support import expected_conditions as ec
|
||||||
@ -259,8 +259,8 @@ class DriverPage(object):
|
|||||||
elif mode == 'right':
|
elif mode == 'right':
|
||||||
self.driver.execute_script(f"window.scrollBy({pixel},0);")
|
self.driver.execute_script(f"window.scrollBy({pixel},0);")
|
||||||
else:
|
else:
|
||||||
raise KeyError(
|
raise ValueError(
|
||||||
"mode must be selected among 'top','bottom','rightmost','leftmost','up','down','left','right'.")
|
"Argument mode can only be 'top', 'bottom', 'rightmost', 'leftmost', 'up', 'down', 'left', 'right'.")
|
||||||
|
|
||||||
def refresh(self) -> None:
|
def refresh(self) -> None:
|
||||||
"""刷新页面"""
|
"""刷新页面"""
|
||||||
@ -276,7 +276,7 @@ class DriverPage(object):
|
|||||||
self.driver.maximize_window()
|
self.driver.maximize_window()
|
||||||
else:
|
else:
|
||||||
if x <= 0 or y <= 0:
|
if x <= 0 or y <= 0:
|
||||||
raise KeyError('x and y must greater than 0.')
|
raise ValueError('Arguments x and y must greater than 0.')
|
||||||
new_x = x or self.driver.get_window_size()['width']
|
new_x = x or self.driver.get_window_size()['width']
|
||||||
new_y = y or self.driver.get_window_size()['height']
|
new_y = y or self.driver.get_window_size()['height']
|
||||||
self.driver.set_window_size(new_x, new_y)
|
self.driver.set_window_size(new_x, new_y)
|
||||||
|
@ -53,7 +53,7 @@ class MixPage(Null, SessionPage, DriverPage):
|
|||||||
elif mode == 'd':
|
elif mode == 'd':
|
||||||
self._driver = True
|
self._driver = True
|
||||||
else:
|
else:
|
||||||
raise KeyError("mode must be 'd' or 's'.")
|
raise ValueError("Argument mode can only be 'd' or 's'.")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self) -> str:
|
def url(self) -> str:
|
||||||
@ -163,9 +163,9 @@ class MixPage(Null, SessionPage, DriverPage):
|
|||||||
path = download_path or self._drission.driver_options['experimental_options']['prefs'][
|
path = download_path or self._drission.driver_options['experimental_options']['prefs'][
|
||||||
'download.default_directory']
|
'download.default_directory']
|
||||||
if not path:
|
if not path:
|
||||||
raise KeyError
|
raise
|
||||||
except KeyError:
|
except:
|
||||||
raise KeyError('Download path not found.')
|
raise IOError('Download path not found.')
|
||||||
|
|
||||||
return super().chrome_downloading(path)
|
return super().chrome_downloading(path)
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class SessionElement(DrissionElement):
|
|||||||
elif isinstance(loc_or_str, tuple) and len(loc_or_str) == 2:
|
elif isinstance(loc_or_str, tuple) and len(loc_or_str) == 2:
|
||||||
loc_or_str = translate_loc_to_xpath(loc_or_str)
|
loc_or_str = translate_loc_to_xpath(loc_or_str)
|
||||||
else:
|
else:
|
||||||
raise ValueError('loc_or_str must be tuple or str.')
|
raise TypeError('Type of loc_or_str can only be tuple or str.')
|
||||||
|
|
||||||
loc_str = None
|
loc_str = None
|
||||||
if loc_or_str[0] == 'xpath':
|
if loc_or_str[0] == 'xpath':
|
||||||
@ -161,7 +161,7 @@ def execute_session_find(page_or_ele: BaseParser,
|
|||||||
"""
|
"""
|
||||||
mode = mode or 'single'
|
mode = mode or 'single'
|
||||||
if mode not in ['single', 'all']:
|
if mode not in ['single', 'all']:
|
||||||
raise ValueError("mode must be 'single' or 'all'.")
|
raise ValueError("Argument mode can only be 'single' or 'all'.")
|
||||||
loc_by, loc_str = loc
|
loc_by, loc_str = loc
|
||||||
msg = result = first = None
|
msg = result = first = None
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user