mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
调整项目结构和部分类名
This commit is contained in:
parent
c6273d9bf2
commit
457eb27566
@ -6,7 +6,7 @@
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from .chromium_driver import BrowserDriver, ChromiumDriver
|
from .chromium_driver import BrowserDriver, ChromiumDriver
|
||||||
from .._units.download_manager import BrowserDownloadManager
|
from .._units.download_manager import DownloadManager
|
||||||
|
|
||||||
|
|
||||||
class Browser(object):
|
class Browser(object):
|
||||||
@ -77,7 +77,7 @@ class Browser(object):
|
|||||||
def connect_to_page(self):
|
def connect_to_page(self):
|
||||||
"""执行与page相关的逻辑"""
|
"""执行与page相关的逻辑"""
|
||||||
if not self._connected:
|
if not self._connected:
|
||||||
self._dl_mgr = BrowserDownloadManager(self)
|
self._dl_mgr = DownloadManager(self)
|
||||||
self._connected = True
|
self._connected = True
|
||||||
|
|
||||||
def run_cdp(self, cmd, **cmd_args):
|
def run_cdp(self, cmd, **cmd_args):
|
||||||
|
@ -7,7 +7,7 @@ from typing import List, Optional, Union
|
|||||||
|
|
||||||
from .chromium_driver import BrowserDriver, ChromiumDriver
|
from .chromium_driver import BrowserDriver, ChromiumDriver
|
||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._units.download_manager import BrowserDownloadManager
|
from .._units.download_manager import DownloadManager
|
||||||
|
|
||||||
|
|
||||||
class Browser(object):
|
class Browser(object):
|
||||||
@ -19,7 +19,7 @@ class Browser(object):
|
|||||||
_frames: dict = ...
|
_frames: dict = ...
|
||||||
_drivers: dict = ...
|
_drivers: dict = ...
|
||||||
_process_id: Optional[int] = ...
|
_process_id: Optional[int] = ...
|
||||||
_dl_mgr: BrowserDownloadManager = ...
|
_dl_mgr: DownloadManager = ...
|
||||||
_connected: bool = ...
|
_connected: bool = ...
|
||||||
|
|
||||||
def __new__(cls, address: str, browser_id: str, page: ChromiumPage): ...
|
def __new__(cls, address: str, browser_id: str, page: ChromiumPage): ...
|
||||||
|
@ -169,7 +169,8 @@ def test_connect(ip, port, timeout=30):
|
|||||||
raise BrowserConnectError(f'\n{ip}:{port}浏览器无法链接。\n请确认:\n1、该端口为浏览器\n'
|
raise BrowserConnectError(f'\n{ip}:{port}浏览器无法链接。\n请确认:\n1、该端口为浏览器\n'
|
||||||
f'2、已添加--remote-allow-origins=*和--remote-debugging-port={port}启动项\n'
|
f'2、已添加--remote-allow-origins=*和--remote-debugging-port={port}启动项\n'
|
||||||
f'3、用户文件夹没有和已打开的浏览器冲突\n'
|
f'3、用户文件夹没有和已打开的浏览器冲突\n'
|
||||||
f'4、如为无界面系统,请使用headless模式\n'
|
f'4、如为无界面系统,请添加--headless=new参数\n'
|
||||||
|
f'5、如果是Linux系统,可能还要添加--no-sandbox启动参数\n'
|
||||||
f'可使用ChromiumOptions设置端口和用户文件夹路径。')
|
f'可使用ChromiumOptions设置端口和用户文件夹路径。')
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,11 +15,13 @@ from .._commons.locator import get_loc
|
|||||||
from .._commons.tools import get_usable_path
|
from .._commons.tools import get_usable_path
|
||||||
from .._commons.web import make_absolute_link, get_ele_txt, format_html, is_js_func, offset_scroll
|
from .._commons.web import make_absolute_link, get_ele_txt, format_html, is_js_func, offset_scroll
|
||||||
from .._units.clicker import Clicker
|
from .._units.clicker import Clicker
|
||||||
from .._units.element_states import ChromiumElementStates, ShadowRootStates
|
from .._units.element_states import ElementStates, ShadowRootStates
|
||||||
|
from .._units.ids import Ids, ElementIds
|
||||||
from .._units.locations import Locations
|
from .._units.locations import Locations
|
||||||
|
from .._units.scroller import ElementScroller
|
||||||
from .._units.select_element import SelectElement
|
from .._units.select_element import SelectElement
|
||||||
from .._units.setter import ChromiumElementSetter
|
from .._units.setter import ChromiumElementSetter
|
||||||
from .._units.waiter import ChromiumElementWaiter
|
from .._units.waiter import ElementWaiter
|
||||||
from ..errors import (ContextLossError, ElementLossError, JavaScriptError, ElementNotFoundError,
|
from ..errors import (ContextLossError, ElementLossError, JavaScriptError, ElementNotFoundError,
|
||||||
CDPError, NoResourceError, AlertExistsError)
|
CDPError, NoResourceError, AlertExistsError)
|
||||||
|
|
||||||
@ -64,7 +66,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
else:
|
else:
|
||||||
raise ElementLossError
|
raise ElementLossError
|
||||||
|
|
||||||
self._ids = ChromiumElementIds(self)
|
self._ids = ElementIds(self)
|
||||||
doc = self.run_js('return this.ownerDocument;')
|
doc = self.run_js('return this.ownerDocument;')
|
||||||
self._doc_id = doc['objectId'] if doc else None
|
self._doc_id = doc['objectId'] if doc else None
|
||||||
|
|
||||||
@ -141,7 +143,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
def states(self):
|
def states(self):
|
||||||
"""返回用于获取元素状态的对象"""
|
"""返回用于获取元素状态的对象"""
|
||||||
if self._states is None:
|
if self._states is None:
|
||||||
self._states = ChromiumElementStates(self)
|
self._states = ElementStates(self)
|
||||||
return self._states
|
return self._states
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -181,7 +183,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
def scroll(self):
|
def scroll(self):
|
||||||
"""用于滚动滚动条的对象"""
|
"""用于滚动滚动条的对象"""
|
||||||
if self._scroll is None:
|
if self._scroll is None:
|
||||||
self._scroll = ChromiumElementScroll(self)
|
self._scroll = ElementScroller(self)
|
||||||
return self._scroll
|
return self._scroll
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -195,7 +197,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
def wait(self):
|
def wait(self):
|
||||||
"""返回用于等待的对象"""
|
"""返回用于等待的对象"""
|
||||||
if self._wait is None:
|
if self._wait is None:
|
||||||
self._wait = ChromiumElementWaiter(self.page, self)
|
self._wait = ElementWaiter(self.page, self)
|
||||||
return self._wait
|
return self._wait
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -1081,33 +1083,6 @@ class ChromiumShadowRoot(BaseElement):
|
|||||||
return r['backendNodeId']
|
return r['backendNodeId']
|
||||||
|
|
||||||
|
|
||||||
class Ids(object):
|
|
||||||
def __init__(self, ele):
|
|
||||||
self._ele = ele
|
|
||||||
|
|
||||||
@property
|
|
||||||
def node_id(self):
|
|
||||||
"""返回元素cdp中的node id"""
|
|
||||||
return self._ele._node_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def obj_id(self):
|
|
||||||
"""返回元素js中的object id"""
|
|
||||||
return self._ele._obj_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def backend_id(self):
|
|
||||||
"""返回backend id"""
|
|
||||||
return self._ele._backend_id
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementIds(Ids):
|
|
||||||
@property
|
|
||||||
def doc_id(self):
|
|
||||||
"""返回所在document的object id"""
|
|
||||||
return self._ele._doc_id
|
|
||||||
|
|
||||||
|
|
||||||
def find_in_chromium_ele(ele, loc, single=True, timeout=None, relative=True):
|
def find_in_chromium_ele(ele, loc, single=True, timeout=None, relative=True):
|
||||||
"""在chromium元素中查找
|
"""在chromium元素中查找
|
||||||
:param ele: ChromiumElement对象
|
:param ele: ChromiumElement对象
|
||||||
@ -1439,116 +1414,6 @@ def send_key(ele, modifier, key):
|
|||||||
ele.page.run_cdp('Input.dispatchKeyEvent', **data)
|
ele.page.run_cdp('Input.dispatchKeyEvent', **data)
|
||||||
|
|
||||||
|
|
||||||
class ChromiumScroll(object):
|
|
||||||
"""用于滚动的对象"""
|
|
||||||
|
|
||||||
def __init__(self, ele):
|
|
||||||
"""
|
|
||||||
:param ele: 元素对象
|
|
||||||
"""
|
|
||||||
self._driver = ele
|
|
||||||
self.t1 = self.t2 = 'this'
|
|
||||||
self._wait_complete = False
|
|
||||||
|
|
||||||
def _run_js(self, js):
|
|
||||||
js = js.format(self.t1, self.t2, self.t2)
|
|
||||||
self._driver.run_js(js)
|
|
||||||
self._wait_scrolled()
|
|
||||||
|
|
||||||
def to_top(self):
|
|
||||||
"""滚动到顶端,水平位置不变"""
|
|
||||||
self._run_js('{}.scrollTo({}.scrollLeft, 0);')
|
|
||||||
|
|
||||||
def to_bottom(self):
|
|
||||||
"""滚动到底端,水平位置不变"""
|
|
||||||
self._run_js('{}.scrollTo({}.scrollLeft, {}.scrollHeight);')
|
|
||||||
|
|
||||||
def to_half(self):
|
|
||||||
"""滚动到垂直中间位置,水平位置不变"""
|
|
||||||
self._run_js('{}.scrollTo({}.scrollLeft, {}.scrollHeight/2);')
|
|
||||||
|
|
||||||
def to_rightmost(self):
|
|
||||||
"""滚动到最右边,垂直位置不变"""
|
|
||||||
self._run_js('{}.scrollTo({}.scrollWidth, {}.scrollTop);')
|
|
||||||
|
|
||||||
def to_leftmost(self):
|
|
||||||
"""滚动到最左边,垂直位置不变"""
|
|
||||||
self._run_js('{}.scrollTo(0, {}.scrollTop);')
|
|
||||||
|
|
||||||
def to_location(self, x, y):
|
|
||||||
"""滚动到指定位置
|
|
||||||
:param x: 水平距离
|
|
||||||
:param y: 垂直距离
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._run_js(f'{{}}.scrollTo({x}, {y});')
|
|
||||||
|
|
||||||
def up(self, pixel=300):
|
|
||||||
"""向上滚动若干像素,水平位置不变
|
|
||||||
:param pixel: 滚动的像素
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
pixel = -pixel
|
|
||||||
self._run_js(f'{{}}.scrollBy(0, {pixel});')
|
|
||||||
|
|
||||||
def down(self, pixel=300):
|
|
||||||
"""向下滚动若干像素,水平位置不变
|
|
||||||
:param pixel: 滚动的像素
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._run_js(f'{{}}.scrollBy(0, {pixel});')
|
|
||||||
|
|
||||||
def left(self, pixel=300):
|
|
||||||
"""向左滚动若干像素,垂直位置不变
|
|
||||||
:param pixel: 滚动的像素
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
pixel = -pixel
|
|
||||||
self._run_js(f'{{}}.scrollBy({pixel}, 0);')
|
|
||||||
|
|
||||||
def right(self, pixel=300):
|
|
||||||
"""向右滚动若干像素,垂直位置不变
|
|
||||||
:param pixel: 滚动的像素
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._run_js(f'{{}}.scrollBy({pixel}, 0);')
|
|
||||||
|
|
||||||
def _wait_scrolled(self):
|
|
||||||
if not self._wait_complete:
|
|
||||||
return
|
|
||||||
|
|
||||||
page = self._driver.page if isinstance(self._driver, ChromiumElement) else self._driver
|
|
||||||
r = page.run_cdp('Page.getLayoutMetrics')
|
|
||||||
x = r['layoutViewport']['pageX']
|
|
||||||
y = r['layoutViewport']['pageY']
|
|
||||||
|
|
||||||
end_time = perf_counter() + self._driver.page.timeout
|
|
||||||
while perf_counter() < end_time:
|
|
||||||
sleep(.1)
|
|
||||||
r = page.run_cdp('Page.getLayoutMetrics')
|
|
||||||
x1 = r['layoutViewport']['pageX']
|
|
||||||
y1 = r['layoutViewport']['pageY']
|
|
||||||
|
|
||||||
if x == x1 and y == y1:
|
|
||||||
break
|
|
||||||
|
|
||||||
x = x1
|
|
||||||
y = y1
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementScroll(ChromiumScroll):
|
|
||||||
def to_see(self, center=None):
|
|
||||||
"""滚动页面直到元素可见
|
|
||||||
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._driver.page.scroll.to_see(self._driver, center=center)
|
|
||||||
|
|
||||||
def to_center(self):
|
|
||||||
"""元素尽量滚动到视口中间"""
|
|
||||||
self._driver.page.scroll.to_see(self._driver, center=True)
|
|
||||||
|
|
||||||
|
|
||||||
class Pseudo(object):
|
class Pseudo(object):
|
||||||
def __init__(self, ele):
|
def __init__(self, ele):
|
||||||
"""
|
"""
|
||||||
|
@ -14,11 +14,13 @@ from .._pages.chromium_frame import ChromiumFrame
|
|||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._pages.web_page import WebPage
|
from .._pages.web_page import WebPage
|
||||||
from .._units.clicker import Clicker
|
from .._units.clicker import Clicker
|
||||||
from .._units.element_states import ShadowRootStates, ChromiumElementStates
|
from .._units.element_states import ShadowRootStates, ElementStates
|
||||||
|
from .._units.ids import Ids, ElementIds
|
||||||
from .._units.locations import Locations
|
from .._units.locations import Locations
|
||||||
|
from .._units.scroller import ElementScroller
|
||||||
from .._units.select_element import SelectElement
|
from .._units.select_element import SelectElement
|
||||||
from .._units.setter import ChromiumElementSetter
|
from .._units.setter import ChromiumElementSetter
|
||||||
from .._units.waiter import ChromiumElementWaiter
|
from .._units.waiter import ElementWaiter
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElement(DrissionElement):
|
class ChromiumElement(DrissionElement):
|
||||||
@ -32,14 +34,14 @@ class ChromiumElement(DrissionElement):
|
|||||||
self._obj_id: str = ...
|
self._obj_id: str = ...
|
||||||
self._backend_id: str = ...
|
self._backend_id: str = ...
|
||||||
self._doc_id: str = ...
|
self._doc_id: str = ...
|
||||||
self._ids: ChromiumElementIds = ...
|
self._ids: ElementIds = ...
|
||||||
self._scroll: ChromiumElementScroll = ...
|
self._scroll: ElementScroller = ...
|
||||||
self._clicker: Clicker = ...
|
self._clicker: Clicker = ...
|
||||||
self._select: SelectElement = ...
|
self._select: SelectElement = ...
|
||||||
self._wait: ChromiumElementWaiter = ...
|
self._wait: ElementWaiter = ...
|
||||||
self._locations: Locations = ...
|
self._locations: Locations = ...
|
||||||
self._set: ChromiumElementSetter = ...
|
self._set: ChromiumElementSetter = ...
|
||||||
self._states: ChromiumElementStates = ...
|
self._states: ElementStates = ...
|
||||||
self._pseudo: Pseudo = ...
|
self._pseudo: Pseudo = ...
|
||||||
|
|
||||||
def __repr__(self) -> str: ...
|
def __repr__(self) -> str: ...
|
||||||
@ -68,7 +70,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
|
|
||||||
# -----------------d模式独有属性-------------------
|
# -----------------d模式独有属性-------------------
|
||||||
@property
|
@property
|
||||||
def ids(self) -> ChromiumElementIds: ...
|
def ids(self) -> ElementIds: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self) -> Tuple[int, int]: ...
|
def size(self) -> Tuple[int, int]: ...
|
||||||
@ -77,7 +79,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
def set(self) -> ChromiumElementSetter: ...
|
def set(self) -> ChromiumElementSetter: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def states(self) -> ChromiumElementStates: ...
|
def states(self) -> ElementStates: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location(self) -> Tuple[int, int]: ...
|
def location(self) -> Tuple[int, int]: ...
|
||||||
@ -95,7 +97,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
def sr(self) -> Union[None, ChromiumShadowRoot]: ...
|
def sr(self) -> Union[None, ChromiumShadowRoot]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scroll(self) -> ChromiumElementScroll: ...
|
def scroll(self) -> ElementScroller: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def click(self) -> Clicker: ...
|
def click(self) -> Clicker: ...
|
||||||
@ -148,7 +150,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wait(self) -> ChromiumElementWaiter: ...
|
def wait(self) -> ElementWaiter: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def select(self) -> SelectElement: ...
|
def select(self) -> SelectElement: ...
|
||||||
@ -301,25 +303,6 @@ class ChromiumShadowRoot(BaseElement):
|
|||||||
def _get_backend_id(self, node_id: str) -> str: ...
|
def _get_backend_id(self, node_id: str) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
class Ids(object):
|
|
||||||
def __init__(self, ele: Union[ChromiumElement, ChromiumShadowRoot]):
|
|
||||||
self._ele: Union[ChromiumElement, ChromiumShadowRoot] = ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def node_id(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def obj_id(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def backend_id(self) -> str: ...
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementIds(Ids):
|
|
||||||
@property
|
|
||||||
def doc_id(self) -> str: ...
|
|
||||||
|
|
||||||
|
|
||||||
def find_in_chromium_ele(ele: ChromiumElement,
|
def find_in_chromium_ele(ele: ChromiumElement,
|
||||||
loc: Union[str, Tuple[str, str]],
|
loc: Union[str, Tuple[str, str]],
|
||||||
single: bool = True,
|
single: bool = True,
|
||||||
@ -364,45 +347,6 @@ def send_enter(ele: ChromiumElement) -> None: ...
|
|||||||
def send_key(ele: ChromiumElement, modifier: int, key: str) -> None: ...
|
def send_key(ele: ChromiumElement, modifier: int, key: str) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumScroll(object):
|
|
||||||
def __init__(self, page_or_ele: Union[ChromiumBase, ChromiumElement, ChromiumFrame]):
|
|
||||||
self.t1: str = ...
|
|
||||||
self.t2: str = ...
|
|
||||||
self._driver: Union[ChromiumPage, ChromiumElement, ChromiumFrame] = ...
|
|
||||||
self._wait_complete: bool = ...
|
|
||||||
|
|
||||||
def _run_js(self, js: str): ...
|
|
||||||
|
|
||||||
def to_top(self) -> None: ...
|
|
||||||
|
|
||||||
def to_bottom(self) -> None: ...
|
|
||||||
|
|
||||||
def to_half(self) -> None: ...
|
|
||||||
|
|
||||||
def to_rightmost(self) -> None: ...
|
|
||||||
|
|
||||||
def to_leftmost(self) -> None: ...
|
|
||||||
|
|
||||||
def to_location(self, x: int, y: int) -> None: ...
|
|
||||||
|
|
||||||
def up(self, pixel: int = 300) -> None: ...
|
|
||||||
|
|
||||||
def down(self, pixel: int = 300) -> None: ...
|
|
||||||
|
|
||||||
def left(self, pixel: int = 300) -> None: ...
|
|
||||||
|
|
||||||
def right(self, pixel: int = 300) -> None: ...
|
|
||||||
|
|
||||||
def _wait_scrolled(self) -> None: ...
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementScroll(ChromiumScroll):
|
|
||||||
|
|
||||||
def to_see(self, center: Union[bool, None] = None) -> None: ...
|
|
||||||
|
|
||||||
def to_center(self) -> None: ...
|
|
||||||
|
|
||||||
|
|
||||||
class Pseudo(object):
|
class Pseudo(object):
|
||||||
def __init__(self, ele: ChromiumElement):
|
def __init__(self, ele: ChromiumElement):
|
||||||
self._ele: ChromiumElement = ...
|
self._ele: ChromiumElement = ...
|
||||||
|
@ -10,18 +10,19 @@ from re import findall
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from time import perf_counter, sleep
|
from time import perf_counter, sleep
|
||||||
|
|
||||||
|
from .._units.scroller import PageScroller
|
||||||
from .._base.base import BasePage
|
from .._base.base import BasePage
|
||||||
from .._commons.constants import ERROR, NoneElement
|
from .._commons.constants import ERROR, NoneElement
|
||||||
from .._commons.locator import get_loc
|
from .._commons.locator import get_loc
|
||||||
from .._commons.tools import get_usable_path
|
from .._commons.tools import get_usable_path
|
||||||
from .._commons.web import location_in_viewport
|
from .._commons.web import location_in_viewport
|
||||||
from .._elements.chromium_element import ChromiumScroll, ChromiumElement, run_js, make_chromium_ele
|
from .._elements.chromium_element import ChromiumElement, run_js, make_chromium_ele
|
||||||
from .._elements.session_element import make_session_ele
|
from .._elements.session_element import make_session_ele
|
||||||
from .._units.action_chains import ActionChains
|
from .._units.action_chains import ActionChains
|
||||||
from .._units.network_listener import NetworkListener
|
from .._units.network_listener import NetworkListener
|
||||||
from .._units.screencast import Screencast
|
from .._units.screencast import Screencast
|
||||||
from .._units.setter import ChromiumBaseSetter
|
from .._units.setter import ChromiumBaseSetter
|
||||||
from .._units.waiter import ChromiumBaseWaiter
|
from .._units.waiter import BaseWaiter
|
||||||
from ..errors import (ContextLossError, ElementLossError, CDPError, TabClosedError, NoRectError, AlertExistsError,
|
from ..errors import (ContextLossError, ElementLossError, CDPError, TabClosedError, NoRectError, AlertExistsError,
|
||||||
GetDocumentError)
|
GetDocumentError)
|
||||||
|
|
||||||
@ -116,7 +117,6 @@ class ChromiumBase(BasePage):
|
|||||||
self._driver.set_listener('Page.frameAttached', self._onFrameAttached)
|
self._driver.set_listener('Page.frameAttached', self._onFrameAttached)
|
||||||
self._driver.set_listener('Page.frameDetached', self._onFrameDetached)
|
self._driver.set_listener('Page.frameDetached', self._onFrameDetached)
|
||||||
|
|
||||||
|
|
||||||
def _get_document(self):
|
def _get_document(self):
|
||||||
if self._is_reading:
|
if self._is_reading:
|
||||||
return
|
return
|
||||||
@ -326,7 +326,7 @@ class ChromiumBase(BasePage):
|
|||||||
"""返回用于滚动滚动条的对象"""
|
"""返回用于滚动滚动条的对象"""
|
||||||
self.wait.load_complete()
|
self.wait.load_complete()
|
||||||
if self._scroll is None:
|
if self._scroll is None:
|
||||||
self._scroll = ChromiumPageScroll(self)
|
self._scroll = PageScroller(self)
|
||||||
return self._scroll
|
return self._scroll
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -343,7 +343,7 @@ class ChromiumBase(BasePage):
|
|||||||
def wait(self):
|
def wait(self):
|
||||||
"""返回用于等待的对象"""
|
"""返回用于等待的对象"""
|
||||||
if self._wait is None:
|
if self._wait is None:
|
||||||
self._wait = ChromiumBaseWaiter(self)
|
self._wait = BaseWaiter(self)
|
||||||
return self._wait
|
return self._wait
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -971,46 +971,6 @@ class ChromiumBase(BasePage):
|
|||||||
return str(path.absolute())
|
return str(path.absolute())
|
||||||
|
|
||||||
|
|
||||||
class ChromiumPageScroll(ChromiumScroll):
|
|
||||||
def __init__(self, page):
|
|
||||||
"""
|
|
||||||
:param page: 页面对象
|
|
||||||
"""
|
|
||||||
super().__init__(page)
|
|
||||||
self.t1 = 'window'
|
|
||||||
self.t2 = 'document.documentElement'
|
|
||||||
|
|
||||||
def to_see(self, loc_or_ele, center=None):
|
|
||||||
"""滚动页面直到元素可见
|
|
||||||
:param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串
|
|
||||||
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
ele = self._driver._ele(loc_or_ele)
|
|
||||||
self._to_see(ele, center)
|
|
||||||
|
|
||||||
def _to_see(self, ele, center):
|
|
||||||
"""执行滚动页面直到元素可见
|
|
||||||
:param ele: 元素对象
|
|
||||||
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
txt = 'true' if center else 'false'
|
|
||||||
ele.run_js(f'this.scrollIntoViewIfNeeded({txt});')
|
|
||||||
if center or (center is not False and ele.states.is_covered):
|
|
||||||
ele.run_js('''function getWindowScrollTop() {var scroll_top = 0;
|
|
||||||
if (document.documentElement && document.documentElement.scrollTop) {
|
|
||||||
scroll_top = document.documentElement.scrollTop;
|
|
||||||
} else if (document.body) {scroll_top = document.body.scrollTop;}
|
|
||||||
return scroll_top;}
|
|
||||||
const { top, height } = this.getBoundingClientRect();
|
|
||||||
const elCenter = top + height / 2;
|
|
||||||
const center = window.innerHeight / 2;
|
|
||||||
window.scrollTo({top: getWindowScrollTop() - (center - elCenter),
|
|
||||||
behavior: 'instant'});''')
|
|
||||||
self._wait_scrolled()
|
|
||||||
|
|
||||||
|
|
||||||
class Timeout(object):
|
class Timeout(object):
|
||||||
"""用于保存d模式timeout信息的类"""
|
"""用于保存d模式timeout信息的类"""
|
||||||
|
|
||||||
|
@ -10,15 +10,16 @@ from .._base.base import BasePage
|
|||||||
from .._base.browser import Browser
|
from .._base.browser import Browser
|
||||||
from .._base.chromium_driver import ChromiumDriver
|
from .._base.chromium_driver import ChromiumDriver
|
||||||
from .._commons.constants import NoneElement
|
from .._commons.constants import NoneElement
|
||||||
from .._elements.chromium_element import ChromiumElement, ChromiumScroll
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._elements.session_element import SessionElement
|
from .._elements.session_element import SessionElement
|
||||||
from .._pages.chromium_frame import ChromiumFrame
|
from .._pages.chromium_frame import ChromiumFrame
|
||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._units.action_chains import ActionChains
|
from .._units.action_chains import ActionChains
|
||||||
from .._units.network_listener import NetworkListener
|
from .._units.network_listener import NetworkListener
|
||||||
from .._units.screencast import Screencast
|
from .._units.screencast import Screencast
|
||||||
|
from .._units.scroller import Scroller, PageScroller
|
||||||
from .._units.setter import ChromiumBaseSetter
|
from .._units.setter import ChromiumBaseSetter
|
||||||
from .._units.waiter import ChromiumBaseWaiter
|
from .._units.waiter import BaseWaiter
|
||||||
|
|
||||||
|
|
||||||
class ChromiumBase(BasePage):
|
class ChromiumBase(BasePage):
|
||||||
@ -37,12 +38,12 @@ class ChromiumBase(BasePage):
|
|||||||
self._first_run: bool = ...
|
self._first_run: bool = ...
|
||||||
self._is_loading: bool = ...
|
self._is_loading: bool = ...
|
||||||
self._page_load_strategy: str = ...
|
self._page_load_strategy: str = ...
|
||||||
self._scroll: ChromiumScroll = ...
|
self._scroll: Scroller = ...
|
||||||
self._url: str = ...
|
self._url: str = ...
|
||||||
self._root_id: str = ...
|
self._root_id: str = ...
|
||||||
self._debug: bool = ...
|
self._debug: bool = ...
|
||||||
self._upload_list: list = ...
|
self._upload_list: list = ...
|
||||||
self._wait: ChromiumBaseWaiter = ...
|
self._wait: BaseWaiter = ...
|
||||||
self._set: ChromiumBaseSetter = ...
|
self._set: ChromiumBaseSetter = ...
|
||||||
self._screencast: Screencast = ...
|
self._screencast: Screencast = ...
|
||||||
self._actions: ActionChains = ...
|
self._actions: ActionChains = ...
|
||||||
@ -137,7 +138,7 @@ class ChromiumBase(BasePage):
|
|||||||
def user_agent(self) -> str: ...
|
def user_agent(self) -> str: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scroll(self) -> ChromiumPageScroll: ...
|
def scroll(self) -> PageScroller: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timeouts(self) -> Timeout: ...
|
def timeouts(self) -> Timeout: ...
|
||||||
@ -146,7 +147,7 @@ class ChromiumBase(BasePage):
|
|||||||
def upload_list(self) -> list: ...
|
def upload_list(self) -> list: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wait(self) -> ChromiumBaseWaiter: ...
|
def wait(self) -> BaseWaiter: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def set(self) -> ChromiumBaseSetter: ...
|
def set(self) -> ChromiumBaseSetter: ...
|
||||||
@ -247,14 +248,6 @@ class ChromiumBase(BasePage):
|
|||||||
timeout: float = None) -> Union[bool, None]: ...
|
timeout: float = None) -> Union[bool, None]: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumPageScroll(ChromiumScroll):
|
|
||||||
def __init__(self, page: ChromiumBase): ...
|
|
||||||
|
|
||||||
def to_see(self, loc_or_ele: Union[str, tuple, ChromiumElement], center: Union[bool, None] = None) -> None: ...
|
|
||||||
|
|
||||||
def _to_see(self, ele: ChromiumElement, center: Union[bool, None]) -> None: ...
|
|
||||||
|
|
||||||
|
|
||||||
class Timeout(object):
|
class Timeout(object):
|
||||||
|
|
||||||
def __init__(self, page: ChromiumBase, implicit=None, page_load=None, script=None):
|
def __init__(self, page: ChromiumBase, implicit=None, page_load=None, script=None):
|
||||||
|
@ -8,10 +8,10 @@ from re import search, findall
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from time import sleep, perf_counter
|
from time import sleep, perf_counter
|
||||||
|
|
||||||
from requests import get
|
|
||||||
|
|
||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._pages.chromium_base import ChromiumBase, ChromiumPageScroll
|
from .._pages.chromium_base import ChromiumBase
|
||||||
|
from .._units.ids import FrameIds
|
||||||
|
from .._units.scroller import FrameScroller
|
||||||
from .._units.setter import ChromiumFrameSetter
|
from .._units.setter import ChromiumFrameSetter
|
||||||
from .._units.waiter import FrameWaiter
|
from .._units.waiter import FrameWaiter
|
||||||
from ..errors import ContextLossError, ElementLossError, GetDocumentError
|
from ..errors import ContextLossError, ElementLossError, GetDocumentError
|
||||||
@ -40,7 +40,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
self._backend_id = ele.ids.backend_id
|
self._backend_id = ele.ids.backend_id
|
||||||
self._frame_ele = ele
|
self._frame_ele = ele
|
||||||
self._states = None
|
self._states = None
|
||||||
self._ids = ChromiumFrameIds(self)
|
self._ids = FrameIds(self)
|
||||||
|
|
||||||
if self._is_inner_frame():
|
if self._is_inner_frame():
|
||||||
self._is_diff_domain = False
|
self._is_diff_domain = False
|
||||||
@ -329,7 +329,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
@property
|
@property
|
||||||
def scroll(self):
|
def scroll(self):
|
||||||
"""返回用于等待的对象"""
|
"""返回用于等待的对象"""
|
||||||
return ChromiumFrameScroll(self)
|
return FrameScroller(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def set(self):
|
def set(self):
|
||||||
@ -658,47 +658,3 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
while self.is_alive:
|
while self.is_alive:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
self.driver.stop()
|
self.driver.stop()
|
||||||
|
|
||||||
|
|
||||||
class ChromiumFrameIds(object):
|
|
||||||
def __init__(self, frame):
|
|
||||||
self._frame = frame
|
|
||||||
|
|
||||||
@property
|
|
||||||
def tab_id(self):
|
|
||||||
"""返回当前标签页id"""
|
|
||||||
return self._frame._tab_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def backend_id(self):
|
|
||||||
"""返回cdp中的node id"""
|
|
||||||
return self._frame._backend_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def obj_id(self):
|
|
||||||
"""返回frame元素的object id"""
|
|
||||||
return self._frame.frame_ele.ids.obj_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def node_id(self):
|
|
||||||
"""返回cdp中的node id"""
|
|
||||||
return self._frame.frame_ele.ids.node_id
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumFrameScroll(ChromiumPageScroll):
|
|
||||||
def __init__(self, frame):
|
|
||||||
"""
|
|
||||||
:param frame: ChromiumFrame对象
|
|
||||||
"""
|
|
||||||
self._driver = frame.doc_ele
|
|
||||||
self.t1 = self.t2 = 'this.documentElement'
|
|
||||||
self._wait_complete = False
|
|
||||||
|
|
||||||
def to_see(self, loc_or_ele, center=None):
|
|
||||||
"""滚动页面直到元素可见
|
|
||||||
:param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串
|
|
||||||
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
ele = loc_or_ele if isinstance(loc_or_ele, ChromiumElement) else self._driver._ele(loc_or_ele)
|
|
||||||
self._to_see(ele, center)
|
|
||||||
|
@ -6,11 +6,15 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union, Tuple, List, Any
|
from typing import Union, Tuple, List, Any
|
||||||
|
|
||||||
from .chromium_base import ChromiumBase, ChromiumPageScroll
|
from .chromium_base import ChromiumBase
|
||||||
from .chromium_page import ChromiumPage
|
from .chromium_page import ChromiumPage
|
||||||
from .chromium_tab import ChromiumTab
|
from .chromium_tab import ChromiumTab
|
||||||
from .web_page import WebPage
|
from .web_page import WebPage
|
||||||
from .._elements.chromium_element import ChromiumElement, Locations, ChromiumElementStates
|
from .._elements.chromium_element import ChromiumElement
|
||||||
|
from .._units.element_states import ElementStates
|
||||||
|
from .._units.ids import FrameIds
|
||||||
|
from .._units.locations import Locations
|
||||||
|
from .._units.scroller import FrameScroller
|
||||||
from .._units.setter import ChromiumFrameSetter
|
from .._units.setter import ChromiumFrameSetter
|
||||||
from .._units.waiter import FrameWaiter
|
from .._units.waiter import FrameWaiter
|
||||||
|
|
||||||
@ -28,8 +32,8 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
self._doc_ele: ChromiumElement = ...
|
self._doc_ele: ChromiumElement = ...
|
||||||
self._is_diff_domain: bool = ...
|
self._is_diff_domain: bool = ...
|
||||||
self.doc_ele: ChromiumElement = ...
|
self.doc_ele: ChromiumElement = ...
|
||||||
self._states: ChromiumElementStates = ...
|
self._states: ElementStates = ...
|
||||||
self._ids: ChromiumFrameIds = ...
|
self._ids: FrameIds = ...
|
||||||
|
|
||||||
def __call__(self,
|
def __call__(self,
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
loc_or_str: Union[Tuple[str, str], str],
|
||||||
@ -57,7 +61,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
def page(self) -> Union[ChromiumPage, WebPage]: ...
|
def page(self) -> Union[ChromiumPage, WebPage]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ids(self) -> ChromiumFrameIds: ...
|
def ids(self) -> FrameIds: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def frame_ele(self) -> ChromiumElement: ...
|
def frame_ele(self) -> ChromiumElement: ...
|
||||||
@ -111,13 +115,13 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
def is_alive(self) -> bool: ...
|
def is_alive(self) -> bool: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scroll(self) -> ChromiumFrameScroll: ...
|
def scroll(self) -> FrameScroller: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def set(self) -> ChromiumFrameSetter: ...
|
def set(self) -> ChromiumFrameSetter: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def states(self) -> ChromiumElementStates: ...
|
def states(self) -> ElementStates: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wait(self) -> FrameWaiter: ...
|
def wait(self) -> FrameWaiter: ...
|
||||||
@ -197,26 +201,3 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
timeout: float = None) -> Union[bool, None]: ...
|
timeout: float = None) -> Union[bool, None]: ...
|
||||||
|
|
||||||
def _is_inner_frame(self) -> bool: ...
|
def _is_inner_frame(self) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumFrameIds(object):
|
|
||||||
def __init__(self, frame: ChromiumFrame):
|
|
||||||
self._frame: ChromiumFrame = ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def tab_id(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def backend_id(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def obj_id(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def node_id(self) -> str: ...
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumFrameScroll(ChromiumPageScroll):
|
|
||||||
def __init__(self, frame: ChromiumFrame) -> None: ...
|
|
||||||
|
|
||||||
def to_see(self, loc_or_ele: Union[str, tuple, ChromiumElement], center: Union[None, bool] = None) -> None: ...
|
|
||||||
|
@ -14,8 +14,8 @@ from .._configs.chromium_options import ChromiumOptions
|
|||||||
from .._pages.chromium_base import ChromiumBase, Timeout
|
from .._pages.chromium_base import ChromiumBase, Timeout
|
||||||
from .._pages.chromium_tab import ChromiumTab
|
from .._pages.chromium_tab import ChromiumTab
|
||||||
from .._units.setter import ChromiumPageSetter
|
from .._units.setter import ChromiumPageSetter
|
||||||
from .._units.tab_rect import ChromiumTabRect
|
from .._units.tab_rect import TabRect
|
||||||
from .._units.waiter import ChromiumPageWaiter
|
from .._units.waiter import PageWaiter
|
||||||
from ..errors import BrowserConnectError
|
from ..errors import BrowserConnectError
|
||||||
|
|
||||||
|
|
||||||
@ -127,14 +127,14 @@ class ChromiumPage(ChromiumBase):
|
|||||||
@property
|
@property
|
||||||
def rect(self):
|
def rect(self):
|
||||||
if self._rect is None:
|
if self._rect is None:
|
||||||
self._rect = ChromiumTabRect(self)
|
self._rect = TabRect(self)
|
||||||
return self._rect
|
return self._rect
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wait(self):
|
def wait(self):
|
||||||
"""返回用于等待的对象"""
|
"""返回用于等待的对象"""
|
||||||
if self._wait is None:
|
if self._wait is None:
|
||||||
self._wait = ChromiumPageWaiter(self)
|
self._wait = PageWaiter(self)
|
||||||
return self._wait
|
return self._wait
|
||||||
|
|
||||||
def get_tab(self, tab_id=None):
|
def get_tab(self, tab_id=None):
|
||||||
|
@ -10,8 +10,8 @@ from .._configs.chromium_options import ChromiumOptions
|
|||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.chromium_tab import ChromiumTab
|
from .._pages.chromium_tab import ChromiumTab
|
||||||
from .._units.setter import ChromiumPageSetter
|
from .._units.setter import ChromiumPageSetter
|
||||||
from .._units.tab_rect import ChromiumTabRect
|
from .._units.tab_rect import TabRect
|
||||||
from .._units.waiter import ChromiumPageWaiter
|
from .._units.waiter import PageWaiter
|
||||||
|
|
||||||
|
|
||||||
class ChromiumPage(ChromiumBase):
|
class ChromiumPage(ChromiumBase):
|
||||||
@ -23,7 +23,7 @@ class ChromiumPage(ChromiumBase):
|
|||||||
self._driver_options: ChromiumOptions = ...
|
self._driver_options: ChromiumOptions = ...
|
||||||
self._main_tab: str = ...
|
self._main_tab: str = ...
|
||||||
self._browser: Browser = ...
|
self._browser: Browser = ...
|
||||||
self._rect: Optional[ChromiumTabRect] = ...
|
self._rect: Optional[TabRect] = ...
|
||||||
|
|
||||||
def _handle_options(self, addr_or_opts: Union[str, ChromiumOptions]) -> str: ...
|
def _handle_options(self, addr_or_opts: Union[str, ChromiumOptions]) -> str: ...
|
||||||
|
|
||||||
@ -41,10 +41,10 @@ class ChromiumPage(ChromiumBase):
|
|||||||
def tabs(self) -> List[str]: ...
|
def tabs(self) -> List[str]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rect(self) -> ChromiumTabRect: ...
|
def rect(self) -> TabRect: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wait(self) -> ChromiumPageWaiter: ...
|
def wait(self) -> PageWaiter: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def main_tab(self) -> str: ...
|
def main_tab(self) -> str: ...
|
||||||
|
@ -10,8 +10,8 @@ from .._commons.web import set_session_cookies, set_browser_cookies
|
|||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.session_page import SessionPage
|
from .._pages.session_page import SessionPage
|
||||||
from .._units.setter import TabSetter, WebPageTabSetter
|
from .._units.setter import TabSetter, WebPageTabSetter
|
||||||
from .._units.tab_rect import ChromiumTabRect
|
from .._units.tab_rect import TabRect
|
||||||
from .._units.waiter import ChromiumTabWaiter
|
from .._units.waiter import TabWaiter
|
||||||
|
|
||||||
|
|
||||||
class ChromiumTab(ChromiumBase):
|
class ChromiumTab(ChromiumBase):
|
||||||
@ -48,7 +48,7 @@ class ChromiumTab(ChromiumBase):
|
|||||||
def rect(self):
|
def rect(self):
|
||||||
"""返回获取窗口坐标和大小的对象"""
|
"""返回获取窗口坐标和大小的对象"""
|
||||||
if self._rect is None:
|
if self._rect is None:
|
||||||
self._rect = ChromiumTabRect(self)
|
self._rect = TabRect(self)
|
||||||
return self._rect
|
return self._rect
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -62,7 +62,7 @@ class ChromiumTab(ChromiumBase):
|
|||||||
def wait(self):
|
def wait(self):
|
||||||
"""返回用于等待的对象"""
|
"""返回用于等待的对象"""
|
||||||
if self._wait is None:
|
if self._wait is None:
|
||||||
self._wait = ChromiumTabWaiter(self)
|
self._wait = TabWaiter(self)
|
||||||
return self._wait
|
return self._wait
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from .._base.browser import Browser
|
|||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._elements.session_element import SessionElement
|
from .._elements.session_element import SessionElement
|
||||||
from .._units.setter import TabSetter, WebPageTabSetter
|
from .._units.setter import TabSetter, WebPageTabSetter
|
||||||
from .._units.waiter import ChromiumTabWaiter
|
from .._units.waiter import TabWaiter
|
||||||
|
|
||||||
|
|
||||||
class ChromiumTab(ChromiumBase):
|
class ChromiumTab(ChromiumBase):
|
||||||
@ -41,7 +41,7 @@ class ChromiumTab(ChromiumBase):
|
|||||||
def set(self) -> TabSetter: ...
|
def set(self) -> TabSetter: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wait(self) -> ChromiumTabWaiter: ...
|
def wait(self) -> TabWaiter: ...
|
||||||
|
|
||||||
|
|
||||||
class WebPageTab(SessionPage, ChromiumTab):
|
class WebPageTab(SessionPage, ChromiumTab):
|
||||||
|
@ -11,7 +11,7 @@ from time import sleep, perf_counter
|
|||||||
from .._commons.tools import get_usable_path
|
from .._commons.tools import get_usable_path
|
||||||
|
|
||||||
|
|
||||||
class BrowserDownloadManager(object):
|
class DownloadManager(object):
|
||||||
|
|
||||||
def __init__(self, browser):
|
def __init__(self, browser):
|
||||||
"""
|
"""
|
||||||
|
@ -5,7 +5,7 @@ from .._base.browser import Browser
|
|||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
|
|
||||||
|
|
||||||
class BrowserDownloadManager(object):
|
class DownloadManager(object):
|
||||||
_browser: Browser = ...
|
_browser: Browser = ...
|
||||||
_page: ChromiumPage = ...
|
_page: ChromiumPage = ...
|
||||||
_missions: Dict[str, DownloadMission] = ...
|
_missions: Dict[str, DownloadMission] = ...
|
||||||
@ -56,7 +56,7 @@ class TabDownloadSettings(object):
|
|||||||
|
|
||||||
class DownloadMission(object):
|
class DownloadMission(object):
|
||||||
tab_id: str = ...
|
tab_id: str = ...
|
||||||
_mgr: BrowserDownloadManager = ...
|
_mgr: DownloadManager = ...
|
||||||
url: str = ...
|
url: str = ...
|
||||||
id: str = ...
|
id: str = ...
|
||||||
path: str = ...
|
path: str = ...
|
||||||
@ -68,7 +68,7 @@ class DownloadMission(object):
|
|||||||
save_path: str = ...
|
save_path: str = ...
|
||||||
_is_done: bool = ...
|
_is_done: bool = ...
|
||||||
|
|
||||||
def __init__(self, mgr: BrowserDownloadManager, tab_id: str, _id: str, path: str, name: str, url: str,
|
def __init__(self, mgr: DownloadManager, tab_id: str, _id: str, path: str, name: str, url: str,
|
||||||
save_path: str): ...
|
save_path: str): ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -7,7 +7,7 @@ from .._commons.web import location_in_viewport
|
|||||||
from ..errors import CDPError, NoRectError
|
from ..errors import CDPError, NoRectError
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementStates(object):
|
class ElementStates(object):
|
||||||
def __init__(self, ele):
|
def __init__(self, ele):
|
||||||
"""
|
"""
|
||||||
:param ele: ChromiumElement
|
:param ele: ChromiumElement
|
||||||
|
@ -8,7 +8,7 @@ from typing import Union, Tuple, List
|
|||||||
from .._elements.chromium_element import ChromiumShadowRoot, ChromiumElement
|
from .._elements.chromium_element import ChromiumShadowRoot, ChromiumElement
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementStates(object):
|
class ElementStates(object):
|
||||||
def __init__(self, ele: ChromiumElement):
|
def __init__(self, ele: ChromiumElement):
|
||||||
self._ele: ChromiumElement = ...
|
self._ele: ChromiumElement = ...
|
||||||
|
|
||||||
|
57
DrissionPage/_units/ids.py
Normal file
57
DrissionPage/_units/ids.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
@Author : g1879
|
||||||
|
@Contact : g1879@qq.com
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Ids(object):
|
||||||
|
def __init__(self, ele):
|
||||||
|
self._ele = ele
|
||||||
|
|
||||||
|
@property
|
||||||
|
def node_id(self):
|
||||||
|
"""返回元素cdp中的node id"""
|
||||||
|
return self._ele._node_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def obj_id(self):
|
||||||
|
"""返回元素js中的object id"""
|
||||||
|
return self._ele._obj_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def backend_id(self):
|
||||||
|
"""返回backend id"""
|
||||||
|
return self._ele._backend_id
|
||||||
|
|
||||||
|
|
||||||
|
class ElementIds(Ids):
|
||||||
|
@property
|
||||||
|
def doc_id(self):
|
||||||
|
"""返回所在document的object id"""
|
||||||
|
return self._ele._doc_id
|
||||||
|
|
||||||
|
|
||||||
|
class FrameIds(object):
|
||||||
|
def __init__(self, frame):
|
||||||
|
self._frame = frame
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tab_id(self):
|
||||||
|
"""返回当前标签页id"""
|
||||||
|
return self._frame._tab_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def backend_id(self):
|
||||||
|
"""返回cdp中的node id"""
|
||||||
|
return self._frame._backend_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def obj_id(self):
|
||||||
|
"""返回frame元素的object id"""
|
||||||
|
return self._frame.frame_ele.ids.obj_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def node_id(self):
|
||||||
|
"""返回cdp中的node id"""
|
||||||
|
return self._frame.frame_ele.ids.node_id
|
45
DrissionPage/_units/ids.pyi
Normal file
45
DrissionPage/_units/ids.pyi
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""
|
||||||
|
@Author : g1879
|
||||||
|
@Contact : g1879@qq.com
|
||||||
|
"""
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from .._pages.chromium_frame import ChromiumFrame
|
||||||
|
from .._elements.chromium_element import ChromiumElement, ChromiumShadowRoot
|
||||||
|
|
||||||
|
|
||||||
|
class Ids(object):
|
||||||
|
def __init__(self, ele: Union[ChromiumElement, ChromiumShadowRoot]):
|
||||||
|
self._ele: Union[ChromiumElement, ChromiumShadowRoot] = ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def node_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def obj_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def backend_id(self) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
|
class ElementIds(Ids):
|
||||||
|
@property
|
||||||
|
def doc_id(self) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
|
class FrameIds(object):
|
||||||
|
def __init__(self, frame: ChromiumFrame):
|
||||||
|
self._frame: ChromiumFrame = ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tab_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def backend_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def obj_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def node_id(self) -> str: ...
|
171
DrissionPage/_units/scroller.py
Normal file
171
DrissionPage/_units/scroller.py
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
from time import sleep, perf_counter
|
||||||
|
|
||||||
|
|
||||||
|
class Scroller(object):
|
||||||
|
"""用于滚动的对象"""
|
||||||
|
|
||||||
|
def __init__(self, ele):
|
||||||
|
"""
|
||||||
|
:param ele: 元素对象
|
||||||
|
"""
|
||||||
|
self._driver = ele
|
||||||
|
self.t1 = self.t2 = 'this'
|
||||||
|
self._wait_complete = False
|
||||||
|
|
||||||
|
def _run_js(self, js):
|
||||||
|
js = js.format(self.t1, self.t2, self.t2)
|
||||||
|
self._driver.run_js(js)
|
||||||
|
self._wait_scrolled()
|
||||||
|
|
||||||
|
def to_top(self):
|
||||||
|
"""滚动到顶端,水平位置不变"""
|
||||||
|
self._run_js('{}.scrollTo({}.scrollLeft, 0);')
|
||||||
|
|
||||||
|
def to_bottom(self):
|
||||||
|
"""滚动到底端,水平位置不变"""
|
||||||
|
self._run_js('{}.scrollTo({}.scrollLeft, {}.scrollHeight);')
|
||||||
|
|
||||||
|
def to_half(self):
|
||||||
|
"""滚动到垂直中间位置,水平位置不变"""
|
||||||
|
self._run_js('{}.scrollTo({}.scrollLeft, {}.scrollHeight/2);')
|
||||||
|
|
||||||
|
def to_rightmost(self):
|
||||||
|
"""滚动到最右边,垂直位置不变"""
|
||||||
|
self._run_js('{}.scrollTo({}.scrollWidth, {}.scrollTop);')
|
||||||
|
|
||||||
|
def to_leftmost(self):
|
||||||
|
"""滚动到最左边,垂直位置不变"""
|
||||||
|
self._run_js('{}.scrollTo(0, {}.scrollTop);')
|
||||||
|
|
||||||
|
def to_location(self, x, y):
|
||||||
|
"""滚动到指定位置
|
||||||
|
:param x: 水平距离
|
||||||
|
:param y: 垂直距离
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._run_js(f'{{}}.scrollTo({x}, {y});')
|
||||||
|
|
||||||
|
def up(self, pixel=300):
|
||||||
|
"""向上滚动若干像素,水平位置不变
|
||||||
|
:param pixel: 滚动的像素
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
pixel = -pixel
|
||||||
|
self._run_js(f'{{}}.scrollBy(0, {pixel});')
|
||||||
|
|
||||||
|
def down(self, pixel=300):
|
||||||
|
"""向下滚动若干像素,水平位置不变
|
||||||
|
:param pixel: 滚动的像素
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._run_js(f'{{}}.scrollBy(0, {pixel});')
|
||||||
|
|
||||||
|
def left(self, pixel=300):
|
||||||
|
"""向左滚动若干像素,垂直位置不变
|
||||||
|
:param pixel: 滚动的像素
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
pixel = -pixel
|
||||||
|
self._run_js(f'{{}}.scrollBy({pixel}, 0);')
|
||||||
|
|
||||||
|
def right(self, pixel=300):
|
||||||
|
"""向右滚动若干像素,垂直位置不变
|
||||||
|
:param pixel: 滚动的像素
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._run_js(f'{{}}.scrollBy({pixel}, 0);')
|
||||||
|
|
||||||
|
def _wait_scrolled(self):
|
||||||
|
if not self._wait_complete:
|
||||||
|
return
|
||||||
|
|
||||||
|
page = self._driver.page if 'ChromiumElement' in str(type(self._driver)) else self._driver
|
||||||
|
r = page.run_cdp('Page.getLayoutMetrics')
|
||||||
|
x = r['layoutViewport']['pageX']
|
||||||
|
y = r['layoutViewport']['pageY']
|
||||||
|
|
||||||
|
end_time = perf_counter() + self._driver.page.timeout
|
||||||
|
while perf_counter() < end_time:
|
||||||
|
sleep(.1)
|
||||||
|
r = page.run_cdp('Page.getLayoutMetrics')
|
||||||
|
x1 = r['layoutViewport']['pageX']
|
||||||
|
y1 = r['layoutViewport']['pageY']
|
||||||
|
|
||||||
|
if x == x1 and y == y1:
|
||||||
|
break
|
||||||
|
|
||||||
|
x = x1
|
||||||
|
y = y1
|
||||||
|
|
||||||
|
|
||||||
|
class ElementScroller(Scroller):
|
||||||
|
def to_see(self, center=None):
|
||||||
|
"""滚动页面直到元素可见
|
||||||
|
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._driver.page.scroll.to_see(self._driver, center=center)
|
||||||
|
|
||||||
|
def to_center(self):
|
||||||
|
"""元素尽量滚动到视口中间"""
|
||||||
|
self._driver.page.scroll.to_see(self._driver, center=True)
|
||||||
|
|
||||||
|
|
||||||
|
class PageScroller(Scroller):
|
||||||
|
def __init__(self, page):
|
||||||
|
"""
|
||||||
|
:param page: 页面对象
|
||||||
|
"""
|
||||||
|
super().__init__(page)
|
||||||
|
self.t1 = 'window'
|
||||||
|
self.t2 = 'document.documentElement'
|
||||||
|
|
||||||
|
def to_see(self, loc_or_ele, center=None):
|
||||||
|
"""滚动页面直到元素可见
|
||||||
|
:param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
|
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
ele = self._driver._ele(loc_or_ele)
|
||||||
|
self._to_see(ele, center)
|
||||||
|
|
||||||
|
def _to_see(self, ele, center):
|
||||||
|
"""执行滚动页面直到元素可见
|
||||||
|
:param ele: 元素对象
|
||||||
|
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
txt = 'true' if center else 'false'
|
||||||
|
ele.run_js(f'this.scrollIntoViewIfNeeded({txt});')
|
||||||
|
if center or (center is not False and ele.states.is_covered):
|
||||||
|
ele.run_js('''function getWindowScrollTop() {var scroll_top = 0;
|
||||||
|
if (document.documentElement && document.documentElement.scrollTop) {
|
||||||
|
scroll_top = document.documentElement.scrollTop;
|
||||||
|
} else if (document.body) {scroll_top = document.body.scrollTop;}
|
||||||
|
return scroll_top;}
|
||||||
|
const { top, height } = this.getBoundingClientRect();
|
||||||
|
const elCenter = top + height / 2;
|
||||||
|
const center = window.innerHeight / 2;
|
||||||
|
window.scrollTo({top: getWindowScrollTop() - (center - elCenter),
|
||||||
|
behavior: 'instant'});''')
|
||||||
|
self._wait_scrolled()
|
||||||
|
|
||||||
|
|
||||||
|
class FrameScroller(PageScroller):
|
||||||
|
def __init__(self, frame):
|
||||||
|
"""
|
||||||
|
:param frame: ChromiumFrame对象
|
||||||
|
"""
|
||||||
|
self._driver = frame.doc_ele
|
||||||
|
self.t1 = self.t2 = 'this.documentElement'
|
||||||
|
self._wait_complete = False
|
||||||
|
|
||||||
|
def to_see(self, loc_or_ele, center=None):
|
||||||
|
"""滚动页面直到元素可见
|
||||||
|
:param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
|
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
ele = loc_or_ele if 'ChromiumElement' in str(type(loc_or_ele)) else self._driver._ele(loc_or_ele)
|
||||||
|
self._to_see(ele, center)
|
73
DrissionPage/_units/scroller.pyi
Normal file
73
DrissionPage/_units/scroller.pyi
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from .._elements.chromium_element import ChromiumElement
|
||||||
|
from .._pages.chromium_base import ChromiumBase
|
||||||
|
from .._pages.chromium_frame import ChromiumFrame
|
||||||
|
from .._pages.chromium_page import ChromiumPage
|
||||||
|
|
||||||
|
|
||||||
|
class Scroller(object):
|
||||||
|
def __init__(self, page_or_ele: Union[ChromiumBase, ChromiumElement, ChromiumFrame]):
|
||||||
|
self.t1: str = ...
|
||||||
|
self.t2: str = ...
|
||||||
|
self._driver: Union[ChromiumPage, ChromiumElement, ChromiumFrame] = ...
|
||||||
|
self._wait_complete: bool = ...
|
||||||
|
|
||||||
|
def _run_js(self, js: str): ...
|
||||||
|
|
||||||
|
def to_top(self) -> None: ...
|
||||||
|
|
||||||
|
def to_bottom(self) -> None: ...
|
||||||
|
|
||||||
|
def to_half(self) -> None: ...
|
||||||
|
|
||||||
|
def to_rightmost(self) -> None: ...
|
||||||
|
|
||||||
|
def to_leftmost(self) -> None: ...
|
||||||
|
|
||||||
|
def to_location(self, x: int, y: int) -> None: ...
|
||||||
|
|
||||||
|
def up(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
|
def down(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
|
def left(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
|
def right(self, pixel: int = 300) -> None: ...
|
||||||
|
|
||||||
|
def _wait_scrolled(self) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class ElementScroller(Scroller):
|
||||||
|
|
||||||
|
def to_see(self, center: Union[bool, None] = None) -> None: ...
|
||||||
|
|
||||||
|
def to_center(self) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class PageScroller(Scroller):
|
||||||
|
def __init__(self, page: ChromiumBase): ...
|
||||||
|
|
||||||
|
def to_see(self, loc_or_ele: Union[str, tuple, ChromiumElement], center: Union[bool, None] = None) -> None: ...
|
||||||
|
|
||||||
|
def _to_see(self, ele: ChromiumElement, center: Union[bool, None]) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class FrameScroller(PageScroller):
|
||||||
|
def __init__(self, frame):
|
||||||
|
"""
|
||||||
|
:param frame: ChromiumFrame对象
|
||||||
|
"""
|
||||||
|
self._driver = frame.doc_ele
|
||||||
|
self.t1 = self.t2 = 'this.documentElement'
|
||||||
|
self._wait_complete = False
|
||||||
|
|
||||||
|
def to_see(self, loc_or_ele, center=None):
|
||||||
|
"""滚动页面直到元素可见
|
||||||
|
:param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
|
:param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
ele = loc_or_ele if isinstance(loc_or_ele, ChromiumElement) else self._driver._ele(loc_or_ele)
|
||||||
|
self._to_see(ele, center)
|
@ -5,7 +5,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class ChromiumTabRect(object):
|
class TabRect(object):
|
||||||
def __init__(self, page):
|
def __init__(self, page):
|
||||||
self._page = page
|
self._page = page
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ from .._pages.chromium_page import ChromiumPage
|
|||||||
from .._pages.chromium_tab import ChromiumTab
|
from .._pages.chromium_tab import ChromiumTab
|
||||||
|
|
||||||
|
|
||||||
class ChromiumTabRect(object):
|
class TabRect(object):
|
||||||
def __init__(self, page: Union[ChromiumPage, ChromiumTab]):
|
def __init__(self, page: Union[ChromiumPage, ChromiumTab]):
|
||||||
self._page: Union[ChromiumPage, ChromiumTab] = ...
|
self._page: Union[ChromiumPage, ChromiumTab] = ...
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from .._commons.constants import Settings
|
|||||||
from ..errors import WaitTimeoutError, NoRectError
|
from ..errors import WaitTimeoutError, NoRectError
|
||||||
|
|
||||||
|
|
||||||
class ChromiumBaseWaiter(object):
|
class BaseWaiter(object):
|
||||||
def __init__(self, page_or_ele):
|
def __init__(self, page_or_ele):
|
||||||
"""
|
"""
|
||||||
:param page_or_ele: 页面对象或元素对象
|
:param page_or_ele: 页面对象或元素对象
|
||||||
@ -190,7 +190,7 @@ class ChromiumBaseWaiter(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ChromiumTabWaiter(ChromiumBaseWaiter):
|
class TabWaiter(BaseWaiter):
|
||||||
|
|
||||||
def downloads_done(self, timeout=None, cancel_if_timeout=True):
|
def downloads_done(self, timeout=None, cancel_if_timeout=True):
|
||||||
"""等待所有浏览器下载任务结束
|
"""等待所有浏览器下载任务结束
|
||||||
@ -219,7 +219,7 @@ class ChromiumTabWaiter(ChromiumBaseWaiter):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ChromiumPageWaiter(ChromiumTabWaiter):
|
class PageWaiter(TabWaiter):
|
||||||
def __init__(self, page):
|
def __init__(self, page):
|
||||||
super().__init__(page)
|
super().__init__(page)
|
||||||
# self._listener = None
|
# self._listener = None
|
||||||
@ -270,7 +270,7 @@ class ChromiumPageWaiter(ChromiumTabWaiter):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementWaiter(object):
|
class ElementWaiter(object):
|
||||||
"""等待元素在dom中某种状态,如删除、显示、隐藏"""
|
"""等待元素在dom中某种状态,如删除、显示、隐藏"""
|
||||||
|
|
||||||
def __init__(self, page, ele):
|
def __init__(self, page, ele):
|
||||||
@ -417,10 +417,10 @@ class ChromiumElementWaiter(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class FrameWaiter(ChromiumBaseWaiter, ChromiumElementWaiter):
|
class FrameWaiter(BaseWaiter, ElementWaiter):
|
||||||
def __init__(self, frame):
|
def __init__(self, frame):
|
||||||
"""
|
"""
|
||||||
:param frame: ChromiumFrame对象
|
:param frame: ChromiumFrame对象
|
||||||
"""
|
"""
|
||||||
super().__init__(frame)
|
super().__init__(frame)
|
||||||
super(ChromiumBaseWaiter, self).__init__(frame, frame.frame_ele)
|
super(BaseWaiter, self).__init__(frame, frame.frame_ele)
|
||||||
|
@ -13,7 +13,7 @@ from .._pages.chromium_frame import ChromiumFrame
|
|||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
|
|
||||||
|
|
||||||
class ChromiumBaseWaiter(object):
|
class BaseWaiter(object):
|
||||||
def __init__(self, page: ChromiumBase):
|
def __init__(self, page: ChromiumBase):
|
||||||
self._driver: ChromiumBase = ...
|
self._driver: ChromiumBase = ...
|
||||||
|
|
||||||
@ -54,12 +54,12 @@ class ChromiumBaseWaiter(object):
|
|||||||
raise_err: bool = None) -> bool: ...
|
raise_err: bool = None) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumTabWaiter(ChromiumBaseWaiter):
|
class TabWaiter(BaseWaiter):
|
||||||
|
|
||||||
def downloads_done(self, timeout: float = None, cancel_if_timeout: bool = True) -> bool: ...
|
def downloads_done(self, timeout: float = None, cancel_if_timeout: bool = True) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumPageWaiter(ChromiumTabWaiter):
|
class PageWaiter(TabWaiter):
|
||||||
_driver: ChromiumPage = ...
|
_driver: ChromiumPage = ...
|
||||||
|
|
||||||
def new_tab(self, timeout: float = None, raise_err: bool = None) -> Union[str, bool]: ...
|
def new_tab(self, timeout: float = None, raise_err: bool = None) -> Union[str, bool]: ...
|
||||||
@ -67,7 +67,7 @@ class ChromiumPageWaiter(ChromiumTabWaiter):
|
|||||||
def all_downloads_done(self, timeout: float = None, cancel_if_timeout: bool = True) -> bool: ...
|
def all_downloads_done(self, timeout: float = None, cancel_if_timeout: bool = True) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementWaiter(object):
|
class ElementWaiter(object):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
page: ChromiumBase,
|
page: ChromiumBase,
|
||||||
ele: ChromiumElement):
|
ele: ChromiumElement):
|
||||||
@ -97,5 +97,5 @@ class ChromiumElementWaiter(object):
|
|||||||
def _wait_state(self, attr: str, mode: bool = False, timeout: float = None, raise_err: bool = None) -> bool: ...
|
def _wait_state(self, attr: str, mode: bool = False, timeout: float = None, raise_err: bool = None) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class FrameWaiter(ChromiumBaseWaiter, ChromiumElementWaiter):
|
class FrameWaiter(BaseWaiter, ElementWaiter):
|
||||||
def __init__(self, frame: ChromiumFrame): ...
|
def __init__(self, frame: ChromiumFrame): ...
|
||||||
|
@ -9,3 +9,5 @@ from ._commons.keys import Keys
|
|||||||
from ._commons.by import By
|
from ._commons.by import By
|
||||||
from ._commons.constants import Settings
|
from ._commons.constants import Settings
|
||||||
from ._commons.tools import wait_until
|
from ._commons.tools import wait_until
|
||||||
|
|
||||||
|
__all__ = ['make_session_ele', 'ActionChains', 'Keys', 'By', 'Settings', 'wait_until']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user