mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
4.0.0b20(+)
增加StorageError; 动作链key_down()和key_up()支持接收按键名称文本
This commit is contained in:
parent
66e52f6fbe
commit
cea156fc86
@ -4,7 +4,7 @@
|
|||||||
@Contact : g1879@qq.com
|
@Contact : g1879@qq.com
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union, Tuple, List, Any
|
from typing import Union, Tuple, List, Any, Literal
|
||||||
|
|
||||||
from .none_element import NoneElement
|
from .none_element import NoneElement
|
||||||
from .._base.base import DrissionElement, BaseElement
|
from .._base.base import DrissionElement, BaseElement
|
||||||
@ -21,6 +21,8 @@ from .._units.setter import ChromiumElementSetter
|
|||||||
from .._units.states import ShadowRootStates, ElementStates
|
from .._units.states import ShadowRootStates, ElementStates
|
||||||
from .._units.waiter import ElementWaiter
|
from .._units.waiter import ElementWaiter
|
||||||
|
|
||||||
|
PIC_TYPE = Literal['jpg', 'jpeg', 'png', 'webp', True]
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElement(DrissionElement):
|
class ChromiumElement(DrissionElement):
|
||||||
|
|
||||||
@ -175,8 +177,8 @@ class ChromiumElement(DrissionElement):
|
|||||||
|
|
||||||
def save(self, path: [str, bool] = None, name: str = None, timeout: float = None) -> str: ...
|
def save(self, path: [str, bool] = None, name: str = None, timeout: float = None) -> str: ...
|
||||||
|
|
||||||
def get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: [bool, str] = None,
|
def get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: PIC_TYPE = None,
|
||||||
as_base64: [bool, str] = None, scroll_to_center: bool = True) -> Union[str, bytes]: ...
|
as_base64: PIC_TYPE = None, scroll_to_center: bool = True) -> Union[str, bytes]: ...
|
||||||
|
|
||||||
def input(self, vals: Any, clear: bool = True, by_js: bool = False) -> None: ...
|
def input(self, vals: Any, clear: bool = True, by_js: bool = False) -> None: ...
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from psutil import process_iter, AccessDenied, NoSuchProcess, ZombieProcess
|
|||||||
|
|
||||||
from .._configs.options_manage import OptionsManager
|
from .._configs.options_manage import OptionsManager
|
||||||
from ..errors import (ContextLostError, ElementLostError, CDPError, PageClosedError, NoRectError, AlertExistsError,
|
from ..errors import (ContextLostError, ElementLostError, CDPError, PageClosedError, NoRectError, AlertExistsError,
|
||||||
WrongURLError)
|
WrongURLError, StorageError)
|
||||||
|
|
||||||
|
|
||||||
def get_usable_path(path, is_file=True, parents=True):
|
def get_usable_path(path, is_file=True, parents=True):
|
||||||
@ -276,6 +276,8 @@ def raise_error(r):
|
|||||||
raise NoRectError
|
raise NoRectError
|
||||||
elif error == 'Cannot navigate to invalid URL':
|
elif error == 'Cannot navigate to invalid URL':
|
||||||
raise WrongURLError(f'无效的url:{r["args"]["url"]}。也许要加上"http://"?')
|
raise WrongURLError(f'无效的url:{r["args"]["url"]}。也许要加上"http://"?')
|
||||||
|
elif error == 'Frame corresponds to an opaque origin and its storage key cannot be serialized':
|
||||||
|
raise StorageError
|
||||||
elif r['type'] == 'call_method_error':
|
elif r['type'] == 'call_method_error':
|
||||||
raise CDPError(f'\n错误:{r["error"]}\nmethod:{r["method"]}\nargs:{r["args"]}\n出现这个错误可能意味着程序有bug,'
|
raise CDPError(f'\n错误:{r["error"]}\nmethod:{r["method"]}\nargs:{r["args"]}\n出现这个错误可能意味着程序有bug,'
|
||||||
'请把错误信息和重现方法告知作者,谢谢。\n报告网站:https://gitee.com/g1879/DrissionPage/issues')
|
'请把错误信息和重现方法告知作者,谢谢。\n报告网站:https://gitee.com/g1879/DrissionPage/issues')
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
@Contact : g1879@qq.com
|
@Contact : g1879@qq.com
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union, Tuple, List, Any, Optional
|
from typing import Union, Tuple, List, Any, Optional, Literal
|
||||||
|
|
||||||
from .._base.base import BasePage
|
from .._base.base import BasePage
|
||||||
from .._base.browser import Browser
|
from .._base.browser import Browser
|
||||||
@ -23,6 +23,8 @@ from .._units.setter import ChromiumBaseSetter
|
|||||||
from .._units.states import PageStates
|
from .._units.states import PageStates
|
||||||
from .._units.waiter import BaseWaiter
|
from .._units.waiter import BaseWaiter
|
||||||
|
|
||||||
|
PIC_TYPE = Literal['jpg', 'jpeg', 'png', 'webp', True]
|
||||||
|
|
||||||
|
|
||||||
class ChromiumBase(BasePage):
|
class ChromiumBase(BasePage):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
@ -214,12 +216,12 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
def get_local_storage(self, item: str = None) -> Union[str, dict, None]: ...
|
def get_local_storage(self, item: str = None) -> Union[str, dict, None]: ...
|
||||||
|
|
||||||
def get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: [bool, str] = None,
|
def get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: PIC_TYPE = None,
|
||||||
as_base64: [bool, str] = None, full_page: bool = False,
|
as_base64: PIC_TYPE = None, full_page: bool = False, left_top: Tuple[int, int] = None,
|
||||||
left_top: Tuple[int, int] = None, right_bottom: Tuple[int, int] = None) -> Union[str, bytes]: ...
|
right_bottom: Tuple[int, int] = None) -> Union[str, bytes]: ...
|
||||||
|
|
||||||
def _get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: [bool, str] = None,
|
def _get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: PIC_TYPE = None,
|
||||||
as_base64: [bool, str] = None, full_page: bool = False, left_top: Tuple[float, float] = None,
|
as_base64: PIC_TYPE = None, full_page: bool = False, left_top: Tuple[float, float] = None,
|
||||||
right_bottom: Tuple[float, float] = None, ele: ChromiumElement = None) -> Union[str, bytes]: ...
|
right_bottom: Tuple[float, float] = None, ele: ChromiumElement = None) -> Union[str, bytes]: ...
|
||||||
|
|
||||||
def clear_cache(self, session_storage: bool = True, local_storage: bool = True, cache: bool = True,
|
def clear_cache(self, session_storage: bool = True, local_storage: bool = True, cache: bool = True,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"""
|
"""
|
||||||
from time import sleep, perf_counter
|
from time import sleep, perf_counter
|
||||||
|
|
||||||
from .._functions.keys import modifierBit, keyDescriptionForString, input_text_or_keys
|
from .._functions.keys import modifierBit, keyDescriptionForString, input_text_or_keys, Keys
|
||||||
from .._functions.web import location_in_viewport
|
from .._functions.web import location_in_viewport
|
||||||
|
|
||||||
|
|
||||||
@ -241,10 +241,11 @@ class Actions:
|
|||||||
return self.move(pixel, 0)
|
return self.move(pixel, 0)
|
||||||
|
|
||||||
def key_down(self, key):
|
def key_down(self, key):
|
||||||
"""按下键盘上的按键
|
"""按下键盘上的按键,
|
||||||
:param key: 按键,特殊字符见Keys
|
:param key: 使用Keys获取的按键,或'DEL'形式按键名称
|
||||||
:return: self
|
:return: self
|
||||||
"""
|
"""
|
||||||
|
key = getattr(Keys, key.upper(), key)
|
||||||
if key in ('\ue009', '\ue008', '\ue00a', '\ue03d'): # 如果上修饰符,添加到变量
|
if key in ('\ue009', '\ue008', '\ue00a', '\ue03d'): # 如果上修饰符,添加到变量
|
||||||
self.modifier |= modifierBit.get(key, 0)
|
self.modifier |= modifierBit.get(key, 0)
|
||||||
return self
|
return self
|
||||||
@ -258,6 +259,7 @@ class Actions:
|
|||||||
:param key: 按键,特殊字符见Keys
|
:param key: 按键,特殊字符见Keys
|
||||||
:return: self
|
:return: self
|
||||||
"""
|
"""
|
||||||
|
key = getattr(Keys, key.upper(), key)
|
||||||
if key in ('\ue009', '\ue008', '\ue00a', '\ue03d'): # 如果上修饰符,添加到变量
|
if key in ('\ue009', '\ue008', '\ue00a', '\ue03d'): # 如果上修饰符,添加到变量
|
||||||
self.modifier ^= modifierBit.get(key, 0)
|
self.modifier ^= modifierBit.get(key, 0)
|
||||||
return self
|
return self
|
||||||
|
@ -3,12 +3,37 @@
|
|||||||
@Author : g1879
|
@Author : g1879
|
||||||
@Contact : g1879@qq.com
|
@Contact : g1879@qq.com
|
||||||
"""
|
"""
|
||||||
from typing import Union, Tuple, Any
|
from typing import Union, Tuple, Any, Literal
|
||||||
|
|
||||||
from .._base.chromium_driver import ChromiumDriver
|
from .._base.chromium_driver import ChromiumDriver
|
||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
|
|
||||||
|
KEYS = Literal['NULL', 'CANCEL', 'HELP', 'BACKSPACE', 'BACK_SPACE',
|
||||||
|
'TAB', 'CLEAR', 'RETURN', 'ENTER', 'SHIFT', 'LEFT_SHIFT', 'CONTROL',
|
||||||
|
'CTRL', 'LEFT_CONTROL', 'ALT', 'LEFT_ALT', 'PAUSE', 'ESCAPE', 'SPACE',
|
||||||
|
'PAGE_UP', 'PAGE_DOWN', 'END', 'HOME', 'LEFT', 'ARROW_LEFT', 'UP',
|
||||||
|
'ARROW_UP', 'RIGHT', 'ARROW_RIGHT', 'DOWN', 'ARROW_DOWN', 'INSERT',
|
||||||
|
'DELETE', 'DEL', 'SEMICOLON', 'EQUALS', 'NUMPAD0', 'NUMPAD1', 'NUMPAD2',
|
||||||
|
'NUMPAD3', 'NUMPAD4', 'NUMPAD5', 'NUMPAD6', 'NUMPAD7', 'NUMPAD8', 'NUMPAD9',
|
||||||
|
'MULTIPLY', 'ADD', 'SUBTRACT', 'DECIMAL', 'DIVIDE', 'F1', 'F2',
|
||||||
|
'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'META', 'COMMAND ',
|
||||||
|
'null', 'cancel', 'help', 'backspace', 'back_space', 'tab', 'clear', 'return', 'enter',
|
||||||
|
'shift', 'left_shift', 'control', 'ctrl', 'left_control', 'alt', 'left_alt', 'pause',
|
||||||
|
'escape', 'space', 'page_up', 'page_down', 'end', 'home', 'left', 'arrow_left', 'up',
|
||||||
|
'arrow_up', 'right', 'arrow_right', 'down', 'arrow_down', 'insert', 'delete', 'del',
|
||||||
|
'semicolon', 'equals', 'numpad0', 'numpad1', 'numpad2', 'numpad3', 'numpad4', 'numpad5',
|
||||||
|
'numpad6', 'numpad7', 'numpad8', 'numpad9', 'multiply', 'add', 'subtract', 'decimal',
|
||||||
|
'divide', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12',
|
||||||
|
'meta', 'command ',
|
||||||
|
'\ue000', '\ue002', '\ue003', '\ue004', '\ue005', '\ue006', '\ue007', '\ue008', '\ue009',
|
||||||
|
'\ue009', '\ue00a', '\ue00b', '\ue00c', '\ue00d', '\ue00e', '\ue00f', '\ue010', '\ue011',
|
||||||
|
'\ue012', '\ue013', '\ue014', '\ue015', '\ue016', '\ue017', '\ue017', '\ue018', '\ue019',
|
||||||
|
'\ue01a', '\ue01b', '\ue01c', '\ue01d', '\ue01e', '\ue01f', '\ue020', '\ue021', '\ue022',
|
||||||
|
'\ue023', '\ue024', '\ue025', '\ue027', '\ue028', '\ue029', '\ue031', '\ue032', '\ue033', '\ue034',
|
||||||
|
'\ue035', '\ue036', '\ue037', '\ue038', '\ue039', '\ue03a', '\ue03b', '\ue03c', '\ue03d', '\ue03d'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Actions:
|
class Actions:
|
||||||
|
|
||||||
@ -60,9 +85,9 @@ class Actions:
|
|||||||
|
|
||||||
def right(self, pixel: int) -> Actions: ...
|
def right(self, pixel: int) -> Actions: ...
|
||||||
|
|
||||||
def key_down(self, key: str) -> Actions: ...
|
def key_down(self, key: KEYS) -> Actions: ...
|
||||||
|
|
||||||
def key_up(self, key: str) -> Actions: ...
|
def key_up(self, key: KEYS) -> Actions: ...
|
||||||
|
|
||||||
def type(self, text: Union[str, list, tuple]) -> Actions: ...
|
def type(self, text: Union[str, list, tuple]) -> Actions: ...
|
||||||
|
|
||||||
|
@ -79,3 +79,7 @@ class WaitTimeoutError(BaseError):
|
|||||||
|
|
||||||
class WrongURLError(BaseError):
|
class WrongURLError(BaseError):
|
||||||
_info = '无效的url。'
|
_info = '无效的url。'
|
||||||
|
|
||||||
|
|
||||||
|
class StorageError(BaseError):
|
||||||
|
_info = '无法操作当前存储数据。'
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
requests
|
requests
|
||||||
lxml
|
lxml
|
||||||
cssselect
|
cssselect
|
||||||
DownloadKit>=2.0.0b0
|
DownloadKit>=2.0.0b1
|
||||||
websocket-client
|
websocket-client
|
||||||
click
|
click
|
||||||
tldextract
|
tldextract
|
||||||
|
Loading…
x
Reference in New Issue
Block a user