mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
maximized()和minimized()改成max()和mini();删除ids属性
This commit is contained in:
parent
dbdb4528ab
commit
bde7fecab3
@ -15,7 +15,6 @@ 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.ids import ShadowRootIds, ElementIds
|
|
||||||
from .._units.rect import ElementRect
|
from .._units.rect import ElementRect
|
||||||
from .._units.scroller import ElementScroller
|
from .._units.scroller import ElementScroller
|
||||||
from .._units.select_element import SelectElement
|
from .._units.select_element import SelectElement
|
||||||
@ -66,7 +65,6 @@ class ChromiumElement(DrissionElement):
|
|||||||
else:
|
else:
|
||||||
raise ElementLossError
|
raise ElementLossError
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -121,10 +119,6 @@ class ChromiumElement(DrissionElement):
|
|||||||
return self.prop('innerText')
|
return self.prop('innerText')
|
||||||
|
|
||||||
# -----------------d模式独有属性-------------------
|
# -----------------d模式独有属性-------------------
|
||||||
@property
|
|
||||||
def ids(self):
|
|
||||||
"""返回获取内置id的对象"""
|
|
||||||
return self._ids
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def set(self):
|
def set(self):
|
||||||
@ -775,7 +769,6 @@ class ChromiumShadowRoot(BaseElement):
|
|||||||
self._obj_id = obj_id
|
self._obj_id = obj_id
|
||||||
self._node_id = self._get_node_id(obj_id)
|
self._node_id = self._get_node_id(obj_id)
|
||||||
self._backend_id = self._get_backend_id(self._node_id)
|
self._backend_id = self._get_backend_id(self._node_id)
|
||||||
self._ids = ShadowRootIds(self)
|
|
||||||
self._states = None
|
self._states = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -805,11 +798,6 @@ class ChromiumShadowRoot(BaseElement):
|
|||||||
"""返回内部的html文本"""
|
"""返回内部的html文本"""
|
||||||
return self.run_js('return this.innerHTML;')
|
return self.run_js('return this.innerHTML;')
|
||||||
|
|
||||||
@property
|
|
||||||
def ids(self):
|
|
||||||
"""返回获取内置id的对象"""
|
|
||||||
return self._ids
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def states(self):
|
def states(self):
|
||||||
"""返回用于获取元素状态的对象"""
|
"""返回用于获取元素状态的对象"""
|
||||||
@ -1104,7 +1092,7 @@ def find_by_xpath(ele, xpath, single, timeout, relative=True):
|
|||||||
type_txt = '9' if single else '7'
|
type_txt = '9' if single else '7'
|
||||||
node_txt = 'this.contentDocument' if ele.tag in FRAME_ELEMENT and not relative else 'this'
|
node_txt = 'this.contentDocument' if ele.tag in FRAME_ELEMENT and not relative else 'this'
|
||||||
js = make_js_for_find_ele_by_xpath(xpath, type_txt, node_txt)
|
js = make_js_for_find_ele_by_xpath(xpath, type_txt, node_txt)
|
||||||
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele.ids.obj_id,
|
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele._obj_id,
|
||||||
returnByValue=False, awaitPromise=True, userGesture=True)
|
returnByValue=False, awaitPromise=True, userGesture=True)
|
||||||
if r['result']['type'] == 'string':
|
if r['result']['type'] == 'string':
|
||||||
return r['result']['value']
|
return r['result']['value']
|
||||||
@ -1112,7 +1100,7 @@ def find_by_xpath(ele, xpath, single, timeout, relative=True):
|
|||||||
if 'exceptionDetails' in r:
|
if 'exceptionDetails' in r:
|
||||||
if 'The result is not a node set' in r['result']['description']:
|
if 'The result is not a node set' in r['result']['description']:
|
||||||
js = make_js_for_find_ele_by_xpath(xpath, '1', node_txt)
|
js = make_js_for_find_ele_by_xpath(xpath, '1', node_txt)
|
||||||
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele.ids.obj_id,
|
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele._obj_id,
|
||||||
returnByValue=False, awaitPromise=True, userGesture=True)
|
returnByValue=False, awaitPromise=True, userGesture=True)
|
||||||
return r['result']['value']
|
return r['result']['value']
|
||||||
else:
|
else:
|
||||||
@ -1121,7 +1109,7 @@ def find_by_xpath(ele, xpath, single, timeout, relative=True):
|
|||||||
end_time = perf_counter() + timeout
|
end_time = perf_counter() + timeout
|
||||||
while (r['result']['subtype'] == 'null'
|
while (r['result']['subtype'] == 'null'
|
||||||
or r['result']['description'] == 'NodeList(0)') and perf_counter() < end_time:
|
or r['result']['description'] == 'NodeList(0)') and perf_counter() < end_time:
|
||||||
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele.ids.obj_id,
|
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele._obj_id,
|
||||||
returnByValue=False, awaitPromise=True, userGesture=True)
|
returnByValue=False, awaitPromise=True, userGesture=True)
|
||||||
|
|
||||||
if single:
|
if single:
|
||||||
@ -1150,13 +1138,13 @@ def find_by_css(ele, selector, single, timeout):
|
|||||||
find_all = '' if single else 'All'
|
find_all = '' if single else 'All'
|
||||||
node_txt = 'this.contentDocument' if ele.tag in ('iframe', 'frame', 'shadow-root') else 'this'
|
node_txt = 'this.contentDocument' if ele.tag in ('iframe', 'frame', 'shadow-root') else 'this'
|
||||||
js = f'function(){{return {node_txt}.querySelector{find_all}("{selector}");}}'
|
js = f'function(){{return {node_txt}.querySelector{find_all}("{selector}");}}'
|
||||||
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele.ids.obj_id,
|
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele._obj_id,
|
||||||
returnByValue=False, awaitPromise=True, userGesture=True)
|
returnByValue=False, awaitPromise=True, userGesture=True)
|
||||||
|
|
||||||
end_time = perf_counter() + timeout
|
end_time = perf_counter() + timeout
|
||||||
while ('exceptionDetails' in r or r['result']['subtype'] == 'null' or
|
while ('exceptionDetails' in r or r['result']['subtype'] == 'null' or
|
||||||
r['result']['description'] == 'NodeList(0)') and perf_counter() < end_time:
|
r['result']['description'] == 'NodeList(0)') and perf_counter() < end_time:
|
||||||
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele.ids.obj_id,
|
r = ele.page.run_cdp_loaded('Runtime.callFunctionOn', functionDeclaration=js, objectId=ele._obj_id,
|
||||||
returnByValue=False, awaitPromise=True, userGesture=True)
|
returnByValue=False, awaitPromise=True, userGesture=True)
|
||||||
|
|
||||||
if 'exceptionDetails' in r:
|
if 'exceptionDetails' in r:
|
||||||
@ -1259,7 +1247,7 @@ def run_js(page_or_ele, script, as_expr=False, timeout=None, args=None):
|
|||||||
"""
|
"""
|
||||||
if isinstance(page_or_ele, (ChromiumElement, ChromiumShadowRoot)):
|
if isinstance(page_or_ele, (ChromiumElement, ChromiumShadowRoot)):
|
||||||
page = page_or_ele.page
|
page = page_or_ele.page
|
||||||
obj_id = page_or_ele.ids.obj_id
|
obj_id = page_or_ele._obj_id
|
||||||
is_page = False
|
is_page = False
|
||||||
else:
|
else:
|
||||||
page = page_or_ele
|
page = page_or_ele
|
||||||
@ -1345,7 +1333,7 @@ def parse_js_result(page, ele, result):
|
|||||||
def convert_argument(arg):
|
def convert_argument(arg):
|
||||||
"""把参数转换成js能够接收的形式"""
|
"""把参数转换成js能够接收的形式"""
|
||||||
if isinstance(arg, ChromiumElement):
|
if isinstance(arg, ChromiumElement):
|
||||||
return {'objectId': arg.ids.obj_id}
|
return {'objectId': arg._obj_id}
|
||||||
|
|
||||||
elif isinstance(arg, (int, float, str, bool)):
|
elif isinstance(arg, (int, float, str, bool)):
|
||||||
return {'value': arg}
|
return {'value': arg}
|
||||||
|
@ -14,7 +14,6 @@ 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.ids import ElementIds, ShadowRootIds
|
|
||||||
from .._units.rect import ElementRect
|
from .._units.rect import ElementRect
|
||||||
from .._units.scroller import ElementScroller
|
from .._units.scroller import ElementScroller
|
||||||
from .._units.select_element import SelectElement
|
from .._units.select_element import SelectElement
|
||||||
@ -32,7 +31,6 @@ 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: ElementIds = ...
|
|
||||||
self._scroll: ElementScroller = ...
|
self._scroll: ElementScroller = ...
|
||||||
self._clicker: Clicker = ...
|
self._clicker: Clicker = ...
|
||||||
self._select: SelectElement = ...
|
self._select: SelectElement = ...
|
||||||
@ -66,8 +64,6 @@ class ChromiumElement(DrissionElement):
|
|||||||
def raw_text(self) -> str: ...
|
def raw_text(self) -> str: ...
|
||||||
|
|
||||||
# -----------------d模式独有属性-------------------
|
# -----------------d模式独有属性-------------------
|
||||||
@property
|
|
||||||
def ids(self) -> ElementIds: ...
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def set(self) -> ChromiumElementSetter: ...
|
def set(self) -> ChromiumElementSetter: ...
|
||||||
@ -211,7 +207,6 @@ class ChromiumShadowRoot(BaseElement):
|
|||||||
|
|
||||||
def __init__(self, parent_ele: ChromiumElement, obj_id: str = None, backend_id: str = None):
|
def __init__(self, parent_ele: ChromiumElement, obj_id: str = None, backend_id: str = None):
|
||||||
self._obj_id: str = ...
|
self._obj_id: str = ...
|
||||||
self._ids: ShadowRootIds = ...
|
|
||||||
self._node_id: str = ...
|
self._node_id: str = ...
|
||||||
self._backend_id: str = ...
|
self._backend_id: str = ...
|
||||||
self.page: ChromiumPage = ...
|
self.page: ChromiumPage = ...
|
||||||
@ -223,9 +218,6 @@ class ChromiumShadowRoot(BaseElement):
|
|||||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str],
|
def __call__(self, loc_or_str: Union[Tuple[str, str], str],
|
||||||
timeout: float = None) -> ChromiumElement: ...
|
timeout: float = None) -> ChromiumElement: ...
|
||||||
|
|
||||||
@property
|
|
||||||
def ids(self) -> ShadowRootIds: ...
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def states(self) -> ShadowRootStates: ...
|
def states(self) -> ShadowRootStates: ...
|
||||||
|
|
||||||
|
@ -334,8 +334,8 @@ def make_session_ele(html_or_ele, loc=None, single=True):
|
|||||||
page = html_or_ele.page
|
page = html_or_ele.page
|
||||||
xpath = html_or_ele.xpath
|
xpath = html_or_ele.xpath
|
||||||
# ChromiumElement,兼容传入的元素在iframe内的情况
|
# ChromiumElement,兼容传入的元素在iframe内的情况
|
||||||
html = html_or_ele.page.run_cdp('DOM.getOuterHTML', objectId=html_or_ele.ids.doc_id)['outerHTML'] \
|
html = html_or_ele.page.run_cdp('DOM.getOuterHTML', objectId=html_or_ele._doc_id)['outerHTML'] \
|
||||||
if html_or_ele.ids.doc_id else html_or_ele.page.html
|
if html_or_ele._doc_id else html_or_ele.page.html
|
||||||
html_or_ele = fromstring(html)
|
html_or_ele = fromstring(html)
|
||||||
html_or_ele = html_or_ele.xpath(xpath)[0]
|
html_or_ele = html_or_ele.xpath(xpath)[0]
|
||||||
|
|
||||||
|
@ -50,6 +50,9 @@ class ChromiumBase(BasePage):
|
|||||||
self._has_alert = False
|
self._has_alert = False
|
||||||
self._ready_state = None
|
self._ready_state = None
|
||||||
self._rect = None
|
self._rect = None
|
||||||
|
self._wait = None
|
||||||
|
self._scroll = None
|
||||||
|
self._upload_list = None
|
||||||
self._doc_got = False # 用于在LoadEventFired和FrameStoppedLoading间标记是否已获取doc
|
self._doc_got = False # 用于在LoadEventFired和FrameStoppedLoading间标记是否已获取doc
|
||||||
|
|
||||||
self._download_path = str(Path('.').absolute())
|
self._download_path = str(Path('.').absolute())
|
||||||
@ -81,9 +84,6 @@ class ChromiumBase(BasePage):
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
self._is_reading = False
|
self._is_reading = False
|
||||||
self._upload_list = None
|
|
||||||
self._wait = None
|
|
||||||
self._scroll = None
|
|
||||||
|
|
||||||
if not tab_id:
|
if not tab_id:
|
||||||
tabs = self.browser.driver.get(f'http://{self.address}/json').json()
|
tabs = self.browser.driver.get(f'http://{self.address}/json').json()
|
||||||
@ -697,7 +697,7 @@ class ChromiumBase(BasePage):
|
|||||||
return
|
return
|
||||||
ele = self._ele(loc_or_ele, raise_err=False)
|
ele = self._ele(loc_or_ele, raise_err=False)
|
||||||
if ele:
|
if ele:
|
||||||
self.run_cdp('DOM.removeNode', nodeId=ele.ids.node_id)
|
self.run_cdp('DOM.removeNode', nodeId=ele._node_id)
|
||||||
|
|
||||||
def get_frame(self, loc_ind_ele, timeout=None):
|
def get_frame(self, loc_ind_ele, timeout=None):
|
||||||
"""获取页面中一个frame对象,可传入定位符、iframe序号、ChromiumFrame对象,序号从1开始
|
"""获取页面中一个frame对象,可传入定位符、iframe序号、ChromiumFrame对象,序号从1开始
|
||||||
|
@ -9,7 +9,6 @@ from time import sleep, perf_counter
|
|||||||
|
|
||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._units.ids import FrameIds
|
|
||||||
from .._units.rect import FrameRect
|
from .._units.rect import FrameRect
|
||||||
from .._units.scroller import FrameScroller
|
from .._units.scroller import FrameScroller
|
||||||
from .._units.setter import ChromiumFrameSetter
|
from .._units.setter import ChromiumFrameSetter
|
||||||
@ -35,12 +34,11 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
self.tab = page.tab if 'ChromiumFrame' in page_type else page
|
self.tab = page.tab if 'ChromiumFrame' in page_type else page
|
||||||
|
|
||||||
self.address = page.address
|
self.address = page.address
|
||||||
node = page.run_cdp('DOM.describeNode', backendNodeId=ele.ids.backend_id)['node']
|
node = page.run_cdp('DOM.describeNode', backendNodeId=ele._backend_id)['node']
|
||||||
self._tab_id = page.tab_id
|
self._tab_id = page.tab_id
|
||||||
self._backend_id = ele.ids.backend_id
|
self._backend_id = ele._backend_id
|
||||||
self._frame_ele = ele
|
self._frame_ele = ele
|
||||||
self._states = None
|
self._states = None
|
||||||
self._ids = FrameIds(self)
|
|
||||||
self._is_init_get_doc = True
|
self._is_init_get_doc = True
|
||||||
|
|
||||||
self._frame_id = node['frameId']
|
self._frame_id = node['frameId']
|
||||||
@ -114,7 +112,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
end_time = perf_counter() + 2
|
end_time = perf_counter() + 2
|
||||||
while perf_counter() < end_time:
|
while perf_counter() < end_time:
|
||||||
node = self._target_page.run_cdp('DOM.describeNode',
|
node = self._target_page.run_cdp('DOM.describeNode',
|
||||||
backendNodeId=self._frame_ele.ids.backend_id)['node']
|
backendNodeId=self._frame_ele._backend_id)['node']
|
||||||
if 'frameId' in node:
|
if 'frameId' in node:
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -189,7 +187,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
while perf_counter() < end_time:
|
while perf_counter() < end_time:
|
||||||
try:
|
try:
|
||||||
if self._is_diff_domain is False:
|
if self._is_diff_domain is False:
|
||||||
node = self._target_page.run_cdp('DOM.describeNode', backendNodeId=self.ids.backend_id)['node']
|
node = self._target_page.run_cdp('DOM.describeNode', backendNodeId=self._backend_id)['node']
|
||||||
self.doc_ele = ChromiumElement(self._target_page,
|
self.doc_ele = ChromiumElement(self._target_page,
|
||||||
backend_id=node['contentDocument']['backendNodeId'])
|
backend_id=node['contentDocument']['backendNodeId'])
|
||||||
|
|
||||||
@ -304,12 +302,18 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
# ----------挂件----------
|
# ----------挂件----------
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def page(self):
|
def _obj_id(self):
|
||||||
return self._page
|
"""返回frame元素的object id"""
|
||||||
|
return self.frame_ele._obj_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ids(self):
|
def _node_id(self):
|
||||||
return self._ids
|
"""返回cdp中的node id"""
|
||||||
|
return self.frame_ele._node_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page(self):
|
||||||
|
return self._page
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def frame_ele(self):
|
def frame_ele(self):
|
||||||
@ -330,7 +334,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
def html(self):
|
def html(self):
|
||||||
"""返回元素outerHTML文本"""
|
"""返回元素outerHTML文本"""
|
||||||
tag = self.tag
|
tag = self.tag
|
||||||
out_html = self._target_page.run_cdp('DOM.getOuterHTML', backendNodeId=self.frame_ele.ids.backend_id)[
|
out_html = self._target_page.run_cdp('DOM.getOuterHTML', backendNodeId=self.frame_ele._backend_id)[
|
||||||
'outerHTML']
|
'outerHTML']
|
||||||
sign = search(rf'<{tag}.*?>', out_html).group(0)
|
sign = search(rf'<{tag}.*?>', out_html).group(0)
|
||||||
return f'{sign}{self.inner_html}</{tag}>'
|
return f'{sign}{self.inner_html}</{tag}>'
|
||||||
@ -391,7 +395,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
return self.doc_ele.run_js('return this.readyState;')
|
return self.doc_ele.run_js('return this.readyState;')
|
||||||
except ContextLossError:
|
except ContextLossError:
|
||||||
try:
|
try:
|
||||||
node = self.run_cdp('DOM.describeNode', backendNodeId=self.frame_ele.ids.backend_id)['node']
|
node = self.run_cdp('DOM.describeNode', backendNodeId=self.frame_ele._backend_id)['node']
|
||||||
doc = ChromiumElement(self._target_page, backend_id=node['contentDocument']['backendNodeId'])
|
doc = ChromiumElement(self._target_page, backend_id=node['contentDocument']['backendNodeId'])
|
||||||
return doc.run_js('return this.readyState;')
|
return doc.run_js('return this.readyState;')
|
||||||
except:
|
except:
|
||||||
|
@ -12,7 +12,6 @@ from .chromium_tab import ChromiumTab
|
|||||||
from .web_page import WebPage
|
from .web_page import WebPage
|
||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._units.states import FrameStates
|
from .._units.states import FrameStates
|
||||||
from .._units.ids import FrameIds
|
|
||||||
from .._units.rect import FrameRect
|
from .._units.rect import FrameRect
|
||||||
from .._units.scroller import FrameScroller
|
from .._units.scroller import FrameScroller
|
||||||
from .._units.setter import ChromiumFrameSetter
|
from .._units.setter import ChromiumFrameSetter
|
||||||
@ -32,12 +31,10 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
self._is_diff_domain: bool = ...
|
self._is_diff_domain: bool = ...
|
||||||
self.doc_ele: ChromiumElement = ...
|
self.doc_ele: ChromiumElement = ...
|
||||||
self._states: FrameStates = ...
|
self._states: FrameStates = ...
|
||||||
self._ids: FrameIds = ...
|
|
||||||
self._is_init_get_doc: bool = ...
|
self._is_init_get_doc: bool = ...
|
||||||
self._rect: FrameRect = ...
|
self._rect: FrameRect = ...
|
||||||
|
|
||||||
def __call__(self,
|
def __call__(self, loc_or_str: Union[Tuple[str, str], str],
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
|
||||||
timeout: float = None) -> Union[ChromiumElement, str]: ...
|
timeout: float = None) -> Union[ChromiumElement, str]: ...
|
||||||
|
|
||||||
def _check_alive(self) -> None: ...
|
def _check_alive(self) -> None: ...
|
||||||
@ -61,9 +58,6 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
@property
|
@property
|
||||||
def page(self) -> Union[ChromiumPage, WebPage]: ...
|
def page(self) -> Union[ChromiumPage, WebPage]: ...
|
||||||
|
|
||||||
@property
|
|
||||||
def ids(self) -> FrameIds: ...
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def frame_ele(self) -> ChromiumElement: ...
|
def frame_ele(self) -> ChromiumElement: ...
|
||||||
|
|
||||||
@ -91,6 +85,12 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
@property
|
@property
|
||||||
def rect(self) -> FrameRect: ...
|
def rect(self) -> FrameRect: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _obj_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _node_id(self) -> str: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def active_ele(self) -> ChromiumElement: ...
|
def active_ele(self) -> ChromiumElement: ...
|
||||||
|
|
||||||
@ -128,52 +128,36 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
|
|
||||||
def parent(self, level_or_loc: Union[tuple, str, int] = 1, index: int = 1) -> Union[ChromiumElement, None]: ...
|
def parent(self, level_or_loc: Union[tuple, str, int] = 1, index: int = 1) -> Union[ChromiumElement, None]: ...
|
||||||
|
|
||||||
def prev(self, filter_loc: Union[tuple, str, int] = '',
|
def prev(self, filter_loc: Union[tuple, str, int] = '', index: int = 1,
|
||||||
index: int = 1,
|
timeout: float = 0, ele_only: bool = True) -> Union[ChromiumElement, str]: ...
|
||||||
timeout: float = 0,
|
|
||||||
ele_only: bool = True) -> Union[ChromiumElement, str]: ...
|
|
||||||
|
|
||||||
def next(self, filter_loc: Union[tuple, str, int] = '',
|
def next(self, filter_loc: Union[tuple, str, int] = '', index: int = 1,
|
||||||
index: int = 1,
|
timeout: float = 0, ele_only: bool = True) -> Union[ChromiumElement, str]: ...
|
||||||
timeout: float = 0,
|
|
||||||
ele_only: bool = True) -> Union[ChromiumElement, str]: ...
|
|
||||||
|
|
||||||
def before(self, filter_loc: Union[tuple, str, int] = '',
|
def before(self, filter_loc: Union[tuple, str, int] = '', index: int = 1,
|
||||||
index: int = 1,
|
timeout: float = None, ele_only: bool = True) -> Union[ChromiumElement, str]: ...
|
||||||
timeout: float = None,
|
|
||||||
ele_only: bool = True) -> Union[ChromiumElement, str]: ...
|
|
||||||
|
|
||||||
def after(self, filter_loc: Union[tuple, str, int] = '',
|
def after(self, filter_loc: Union[tuple, str, int] = '', index: int = 1,
|
||||||
index: int = 1,
|
timeout: float = None, ele_only: bool = True) -> Union[ChromiumElement, str]: ...
|
||||||
timeout: float = None,
|
|
||||||
ele_only: bool = True) -> Union[ChromiumElement, str]: ...
|
|
||||||
|
|
||||||
def prevs(self, filter_loc: Union[tuple, str] = '',
|
def prevs(self, filter_loc: Union[tuple, str] = '', timeout: float = 0,
|
||||||
timeout: float = 0,
|
|
||||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def nexts(self, filter_loc: Union[tuple, str] = '',
|
def nexts(self, filter_loc: Union[tuple, str] = '', timeout: float = 0,
|
||||||
timeout: float = 0,
|
|
||||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def befores(self, filter_loc: Union[tuple, str] = '',
|
def befores(self, filter_loc: Union[tuple, str] = '', timeout: float = None,
|
||||||
timeout: float = None,
|
|
||||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def afters(self, filter_loc: Union[tuple, str] = '',
|
def afters(self, filter_loc: Union[tuple, str] = '', timeout: float = None,
|
||||||
timeout: float = None,
|
|
||||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||||
|
|
||||||
def get_screenshot(self, path: [str, Path] = None, name: str = None,
|
def get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: [bool, str] = None,
|
||||||
as_bytes: [bool, str] = None,
|
|
||||||
as_base64: [bool, str] = None) -> Union[str, bytes]: ...
|
as_base64: [bool, str] = None) -> Union[str, bytes]: ...
|
||||||
|
|
||||||
def _get_screenshot(self, path: [str, Path] = None, name: str = None,
|
def _get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: [bool, str] = None,
|
||||||
as_bytes: [bool, str] = None, as_base64: [bool, str] = None,
|
as_base64: [bool, str] = None, full_page: bool = False, left_top: Tuple[int, int] = None,
|
||||||
full_page: bool = False,
|
right_bottom: Tuple[int, int] = None, ele: ChromiumElement = None) -> Union[str, bytes]: ...
|
||||||
left_top: Tuple[int, int] = None,
|
|
||||||
right_bottom: Tuple[int, int] = None,
|
|
||||||
ele: ChromiumElement = None) -> Union[str, bytes]: ...
|
|
||||||
|
|
||||||
def _find_elements(self, loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
def _find_elements(self, loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
||||||
timeout: float = None, single: bool = True, relative: bool = False, raise_err: bool = None) \
|
timeout: float = None, single: bool = True, relative: bool = False, raise_err: bool = None) \
|
||||||
|
@ -78,7 +78,7 @@ class Clicker(object):
|
|||||||
try:
|
try:
|
||||||
r = self._ele.page.run_cdp('DOM.getNodeForLocation', x=x, y=y, includeUserAgentShadowDOM=True,
|
r = self._ele.page.run_cdp('DOM.getNodeForLocation', x=x, y=y, includeUserAgentShadowDOM=True,
|
||||||
ignorePointerEventsNone=True)
|
ignorePointerEventsNone=True)
|
||||||
if r['backendNodeId'] != self._ele.ids.backend_id:
|
if r['backendNodeId'] != self._ele._backend_id:
|
||||||
vx, vy = self._ele.rect.viewport_midpoint
|
vx, vy = self._ele.rect.viewport_midpoint
|
||||||
else:
|
else:
|
||||||
vx, vy = self._ele.rect.viewport_click_point
|
vx, vy = self._ele.rect.viewport_click_point
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
# -*- coding:utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Author : g1879
|
|
||||||
@Contact : g1879@qq.com
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class ShadowRootIds(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(ShadowRootIds):
|
|
||||||
@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
|
|
@ -1,45 +0,0 @@
|
|||||||
# -*- coding:utf-8 -*-
|
|
||||||
"""
|
|
||||||
@Author : g1879
|
|
||||||
@Contact : g1879@qq.com
|
|
||||||
"""
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from .._elements.chromium_element import ChromiumElement, ChromiumShadowRoot
|
|
||||||
from .._pages.chromium_frame import ChromiumFrame
|
|
||||||
|
|
||||||
|
|
||||||
class ShadowRootIds(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(ShadowRootIds):
|
|
||||||
@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: ...
|
|
@ -99,7 +99,7 @@ class ElementRect(object):
|
|||||||
:param quad: 方框类型,margin border padding
|
:param quad: 方框类型,margin border padding
|
||||||
:return: 四个角坐标
|
:return: 四个角坐标
|
||||||
"""
|
"""
|
||||||
return self._ele.page.run_cdp('DOM.getBoxModel', backendNodeId=self._ele.ids.backend_id)['model'][quad]
|
return self._ele.page.run_cdp('DOM.getBoxModel', backendNodeId=self._ele._backend_id)['model'][quad]
|
||||||
|
|
||||||
def _get_page_coord(self, x, y):
|
def _get_page_coord(self, x, y):
|
||||||
"""根据视口坐标获取绝对坐标"""
|
"""根据视口坐标获取绝对坐标"""
|
||||||
|
@ -413,7 +413,7 @@ class ChromiumElementSetter(object):
|
|||||||
:param value: 属性值
|
:param value: 属性值
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
self._ele.page.run_cdp('DOM.setAttributeValue', nodeId=self._ele.ids.node_id, name=attr, value=str(value))
|
self._ele.page.run_cdp('DOM.setAttributeValue', nodeId=self._ele._node_id, name=attr, value=str(value))
|
||||||
|
|
||||||
def prop(self, prop, value):
|
def prop(self, prop, value):
|
||||||
"""设置元素property属性
|
"""设置元素property属性
|
||||||
@ -508,14 +508,14 @@ class WindowSetter(object):
|
|||||||
self._page = page
|
self._page = page
|
||||||
self._window_id = self._get_info()['windowId']
|
self._window_id = self._get_info()['windowId']
|
||||||
|
|
||||||
def maximized(self):
|
def max(self):
|
||||||
"""窗口最大化"""
|
"""窗口最大化"""
|
||||||
s = self._get_info()['bounds']['windowState']
|
s = self._get_info()['bounds']['windowState']
|
||||||
if s in ('fullscreen', 'minimized'):
|
if s in ('fullscreen', 'minimized'):
|
||||||
self._perform({'windowState': 'normal'})
|
self._perform({'windowState': 'normal'})
|
||||||
self._perform({'windowState': 'maximized'})
|
self._perform({'windowState': 'maximized'})
|
||||||
|
|
||||||
def minimized(self):
|
def mini(self):
|
||||||
"""窗口最小化"""
|
"""窗口最小化"""
|
||||||
s = self._get_info()['bounds']['windowState']
|
s = self._get_info()['bounds']['windowState']
|
||||||
if s == 'fullscreen':
|
if s == 'fullscreen':
|
||||||
@ -575,6 +575,16 @@ class WindowSetter(object):
|
|||||||
"""
|
"""
|
||||||
self._page.run_cdp('Browser.setWindowBounds', windowId=self._window_id, bounds=bounds)
|
self._page.run_cdp('Browser.setWindowBounds', windowId=self._window_id, bounds=bounds)
|
||||||
|
|
||||||
|
# ------------即将废除----------
|
||||||
|
|
||||||
|
def maximized(self):
|
||||||
|
"""窗口最大化"""
|
||||||
|
self.max()
|
||||||
|
|
||||||
|
def minimized(self):
|
||||||
|
"""窗口最小化"""
|
||||||
|
self.mini()
|
||||||
|
|
||||||
|
|
||||||
class PageWindowSetter(WindowSetter):
|
class PageWindowSetter(WindowSetter):
|
||||||
def hide(self):
|
def hide(self):
|
||||||
|
@ -191,9 +191,9 @@ class WindowSetter(object):
|
|||||||
self._page: ChromiumBase = ...
|
self._page: ChromiumBase = ...
|
||||||
self._window_id: str = ...
|
self._window_id: str = ...
|
||||||
|
|
||||||
def maximized(self) -> None: ...
|
def max(self) -> None: ...
|
||||||
|
|
||||||
def minimized(self) -> None: ...
|
def mini(self) -> None: ...
|
||||||
|
|
||||||
def fullscreen(self) -> None: ...
|
def fullscreen(self) -> None: ...
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class ElementStates(object):
|
|||||||
except CDPError:
|
except CDPError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if r.get('backendNodeId') != self._ele.ids.backend_id:
|
if r.get('backendNodeId') != self._ele._backend_id:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@ -98,7 +98,7 @@ class ShadowRootStates(object):
|
|||||||
def is_alive(self):
|
def is_alive(self):
|
||||||
"""返回元素是否仍在DOM中"""
|
"""返回元素是否仍在DOM中"""
|
||||||
try:
|
try:
|
||||||
self._ele.page.run_cdp('DOM.describeNode', backendNodeId=self._ele.ids.backend_id)
|
self._ele.page.run_cdp('DOM.describeNode', backendNodeId=self._ele._backend_id)
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
@ -145,7 +145,7 @@ class FrameStates(object):
|
|||||||
"""返回frame元素是否可用,且里面仍挂载有frame"""
|
"""返回frame元素是否可用,且里面仍挂载有frame"""
|
||||||
try:
|
try:
|
||||||
node = self._frame._target_page.run_cdp('DOM.describeNode',
|
node = self._frame._target_page.run_cdp('DOM.describeNode',
|
||||||
backendNodeId=self._frame._frame_ele.ids.backend_id)['node']
|
backendNodeId=self._frame._frame_ele._backend_id)['node']
|
||||||
except (ElementLossError, PageClosedError):
|
except (ElementLossError, PageClosedError):
|
||||||
return False
|
return False
|
||||||
return 'frameId' in node
|
return 'frameId' in node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user