mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
一些修改(+)
fullscreen()改为full(); corners返回tuple; Frame增加states.is_displayed和states.is_loading; has_alert移到states中
This commit is contained in:
parent
731d40a891
commit
545b7a0732
@ -1287,7 +1287,7 @@ def run_js(page_or_ele, script, as_expr=False, timeout=None, args=None):
|
|||||||
obj_id = page_or_ele._root_id
|
obj_id = page_or_ele._root_id
|
||||||
is_page = True
|
is_page = True
|
||||||
|
|
||||||
if page.has_alert:
|
if page.states.has_alert:
|
||||||
raise AlertExistsError
|
raise AlertExistsError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1309,7 +1309,7 @@ def run_js(page_or_ele, script, as_expr=False, timeout=None, args=None):
|
|||||||
else:
|
else:
|
||||||
raise ElementLostError('原来获取到的元素对象已不在页面内。')
|
raise ElementLostError('原来获取到的元素对象已不在页面内。')
|
||||||
|
|
||||||
if res is None and page.driver.has_alert: # 存在alert的情况
|
if res is None and page.states.has_alert: # 存在alert的情况
|
||||||
return None
|
return None
|
||||||
|
|
||||||
exceptionDetails = res.get('exceptionDetails')
|
exceptionDetails = res.get('exceptionDetails')
|
||||||
|
@ -426,11 +426,6 @@ class ChromiumBase(BasePage):
|
|||||||
"""返回等待上传文件列表"""
|
"""返回等待上传文件列表"""
|
||||||
return self._upload_list
|
return self._upload_list
|
||||||
|
|
||||||
@property
|
|
||||||
def has_alert(self):
|
|
||||||
"""返回是否存在提示框"""
|
|
||||||
return self._has_alert
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _js_ready_state(self):
|
def _js_ready_state(self):
|
||||||
"""返回js获取的ready state信息"""
|
"""返回js获取的ready state信息"""
|
||||||
|
@ -162,9 +162,6 @@ class ChromiumBase(BasePage):
|
|||||||
@property
|
@property
|
||||||
def states(self) -> PageStates: ...
|
def states(self) -> PageStates: ...
|
||||||
|
|
||||||
@property
|
|
||||||
def has_alert(self) -> bool: ...
|
|
||||||
|
|
||||||
def run_js(self, script: str, *args, as_expr: bool = False, timeout: float = None) -> Any: ...
|
def run_js(self, script: str, *args, as_expr: bool = False, timeout: float = None) -> Any: ...
|
||||||
|
|
||||||
def run_js_loaded(self, script: str, *args, as_expr: bool = False, timeout: float = None) -> Any: ...
|
def run_js_loaded(self, script: str, *args, as_expr: bool = False, timeout: float = None) -> Any: ...
|
||||||
|
@ -349,7 +349,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
self._has_session = None
|
self._has_session = None
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""关闭标签页"""
|
"""关闭标签页和Session"""
|
||||||
if self._has_driver:
|
if self._has_driver:
|
||||||
self.close_tabs(self.tab_id)
|
self.close_tabs(self.tab_id)
|
||||||
if self._session:
|
if self._session:
|
||||||
|
@ -131,6 +131,8 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
|
|
||||||
def close_session(self) -> None: ...
|
def close_session(self) -> None: ...
|
||||||
|
|
||||||
|
def close(self) -> None: ...
|
||||||
|
|
||||||
# ----------------重写SessionPage的函数-----------------------
|
# ----------------重写SessionPage的函数-----------------------
|
||||||
def post(self,
|
def post(self,
|
||||||
url: str,
|
url: str,
|
||||||
|
@ -19,14 +19,13 @@ class ElementRect(object):
|
|||||||
r = self._ele.page.run_cdp_loaded('Page.getLayoutMetrics')['visualViewport']
|
r = self._ele.page.run_cdp_loaded('Page.getLayoutMetrics')['visualViewport']
|
||||||
sx = r['pageX']
|
sx = r['pageX']
|
||||||
sy = r['pageY']
|
sy = r['pageY']
|
||||||
return [(vr[0] + sx, vr[1] + sy), (vr[2] + sx, vr[3] + sy),
|
return [(vr[0] + sx, vr[1] + sy), (vr[2] + sx, vr[3] + sy), (vr[4] + sx, vr[5] + sy), (vr[6] + sx, vr[7] + sy)]
|
||||||
(vr[4] + sx, vr[5] + sy), (vr[6] + sx, vr[7] + sy)]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def viewport_corners(self):
|
def viewport_corners(self):
|
||||||
"""返回元素四个角视口坐标,顺序:坐上、右上、右下、左下,没有大小的元素抛出NoRectError"""
|
"""返回元素四个角视口坐标,顺序:坐上、右上、右下、左下,没有大小的元素抛出NoRectError"""
|
||||||
r = self._get_viewport_rect('border')
|
r = self._get_viewport_rect('border')
|
||||||
return [(r[0], r[1]), (r[2], r[3]), (r[4], r[5]), (r[6], r[7])]
|
return (r[0], r[1]), (r[2], r[3]), (r[4], r[5]), (r[6], r[7])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
@ -188,12 +187,12 @@ class FrameRect(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def location(self):
|
def location(self):
|
||||||
"""返回元素左上角的绝对坐标"""
|
"""返回iframe元素左上角的绝对坐标"""
|
||||||
return self._frame.frame_ele.rect.location
|
return self._frame.frame_ele.rect.location
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def viewport_location(self):
|
def viewport_location(self):
|
||||||
"""返回视口在屏幕中坐标,左上角为(0, 0)"""
|
"""返回元素在视口中坐标,左上角为(0, 0)"""
|
||||||
return self._frame.frame_ele.rect.viewport_location
|
return self._frame.frame_ele.rect.viewport_location
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -49,10 +49,10 @@ class ElementRect(object):
|
|||||||
def screen_click_point(self) -> Tuple[float, float]: ...
|
def screen_click_point(self) -> Tuple[float, float]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def corners(self) -> List[Tuple[float, float], ...]: ...
|
def corners(self) -> Tuple[Tuple[float, float], ...]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def viewport_corners(self) -> List[Tuple[float, float], ...]: ...
|
def viewport_corners(self) -> Tuple[Tuple[float, float], ...]: ...
|
||||||
|
|
||||||
def _get_viewport_rect(self, quad: str) -> Union[list, None]: ...
|
def _get_viewport_rect(self, quad: str) -> Union[list, None]: ...
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ class FrameRect(object):
|
|||||||
def viewport_size(self) -> Tuple[float, float]: ...
|
def viewport_size(self) -> Tuple[float, float]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def corners(self) -> List[Tuple[float, float], ...]: ...
|
def corners(self) -> Tuple[Tuple[float, float], ...]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def viewport_corners(self) -> List[Tuple[float, float], ...]: ...
|
def viewport_corners(self) -> Tuple[Tuple[float, float], ...]: ...
|
||||||
|
@ -572,7 +572,7 @@ class WindowSetter(object):
|
|||||||
self._perform({'windowState': 'normal'})
|
self._perform({'windowState': 'normal'})
|
||||||
self._perform({'windowState': 'minimized'})
|
self._perform({'windowState': 'minimized'})
|
||||||
|
|
||||||
def fullscreen(self):
|
def full(self):
|
||||||
"""设置窗口为全屏"""
|
"""设置窗口为全屏"""
|
||||||
s = self._get_info()['bounds']['windowState']
|
s = self._get_info()['bounds']['windowState']
|
||||||
if s == 'minimized':
|
if s == 'minimized':
|
||||||
@ -635,6 +635,10 @@ class WindowSetter(object):
|
|||||||
"""窗口最小化"""
|
"""窗口最小化"""
|
||||||
self.mini()
|
self.mini()
|
||||||
|
|
||||||
|
def fullscreen(self):
|
||||||
|
"""设置窗口为全屏"""
|
||||||
|
self.full()
|
||||||
|
|
||||||
|
|
||||||
class PageWindowSetter(WindowSetter):
|
class PageWindowSetter(WindowSetter):
|
||||||
def hide(self):
|
def hide(self):
|
||||||
|
@ -207,7 +207,7 @@ class WindowSetter(object):
|
|||||||
|
|
||||||
def mini(self) -> None: ...
|
def mini(self) -> None: ...
|
||||||
|
|
||||||
def fullscreen(self) -> None: ...
|
def full(self) -> None: ...
|
||||||
|
|
||||||
def normal(self) -> None: ...
|
def normal(self) -> None: ...
|
||||||
|
|
||||||
|
@ -132,6 +132,11 @@ class PageStates(object):
|
|||||||
"""返回当前页面加载状态,'loading' 'interactive' 'complete'"""
|
"""返回当前页面加载状态,'loading' 'interactive' 'complete'"""
|
||||||
return self._page._ready_state
|
return self._page._ready_state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_alert(self):
|
||||||
|
"""返回当前页面加载状态,'loading' 'interactive' 'complete'"""
|
||||||
|
return self._page._has_alert
|
||||||
|
|
||||||
|
|
||||||
class FrameStates(object):
|
class FrameStates(object):
|
||||||
def __init__(self, frame):
|
def __init__(self, frame):
|
||||||
@ -140,6 +145,11 @@ class FrameStates(object):
|
|||||||
"""
|
"""
|
||||||
self._frame = frame
|
self._frame = frame
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_loading(self):
|
||||||
|
"""返回页面是否在加载状态"""
|
||||||
|
return self._frame._is_loading
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_alive(self):
|
def is_alive(self):
|
||||||
"""返回frame元素是否可用,且里面仍挂载有frame"""
|
"""返回frame元素是否可用,且里面仍挂载有frame"""
|
||||||
@ -152,4 +162,12 @@ class FrameStates(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def ready_state(self):
|
def ready_state(self):
|
||||||
|
"""返回加载状态"""
|
||||||
return self._frame._ready_state
|
return self._frame._ready_state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_displayed(self):
|
||||||
|
"""返回iframe是否显示"""
|
||||||
|
return not (self._frame.frame_ele.style('visibility') == 'hidden'
|
||||||
|
or self._frame.frame_ele.run_js('return this.offsetParent === null;')
|
||||||
|
or self._frame.frame_ele.style('display') == 'none')
|
||||||
|
@ -69,11 +69,17 @@ class PageStates(object):
|
|||||||
@property
|
@property
|
||||||
def ready_state(self) -> Optional[str]: ...
|
def ready_state(self) -> Optional[str]: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_alert(self) -> bool: ...
|
||||||
|
|
||||||
|
|
||||||
class FrameStates(object):
|
class FrameStates(object):
|
||||||
def __init__(self, frame: ChromiumFrame):
|
def __init__(self, frame: ChromiumFrame):
|
||||||
self._frame: ChromiumFrame = ...
|
self._frame: ChromiumFrame = ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_loading(self) -> bool: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_alive(self) -> bool: ...
|
def is_alive(self) -> bool: ...
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user