mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
增加get_frame()方法
This commit is contained in:
parent
55314f99d0
commit
cb6fe6d68b
@ -33,7 +33,7 @@ class ChromiumBase(BasePage):
|
|||||||
:param timeout: 超时时间
|
:param timeout: 超时时间
|
||||||
"""
|
"""
|
||||||
self._is_loading = None
|
self._is_loading = None
|
||||||
self._root_id = None
|
self._root_id = None # object id
|
||||||
self._debug = False
|
self._debug = False
|
||||||
self._debug_recorder = None
|
self._debug_recorder = None
|
||||||
self._tab_obj = None
|
self._tab_obj = None
|
||||||
@ -572,6 +572,26 @@ class ChromiumBase(BasePage):
|
|||||||
if ele:
|
if ele:
|
||||||
self.run_cdp('DOM.removeNode', nodeId=ele.ids.node_id)
|
self.run_cdp('DOM.removeNode', nodeId=ele.ids.node_id)
|
||||||
|
|
||||||
|
def get_frame(self, loc_ind_ele):
|
||||||
|
"""获取页面中一个frame对象,可传入定位符、iframe序号、ChromiumFrame对象,序号从1开始
|
||||||
|
:param loc_ind_ele: 定位符、iframe序号、ChromiumFrame对象
|
||||||
|
:return: ChromiumFrame对象
|
||||||
|
"""
|
||||||
|
if isinstance(loc_ind_ele, (str, tuple)):
|
||||||
|
ele = self._ele(loc_ind_ele)
|
||||||
|
if ele and not str(type(ele)).endswith(".ChromiumFrame'>"):
|
||||||
|
raise RuntimeError('该定位符不是指向frame元素。')
|
||||||
|
return ele
|
||||||
|
elif isinstance(loc_ind_ele, int):
|
||||||
|
if loc_ind_ele < 1:
|
||||||
|
raise ValueError('序号必须大于0。')
|
||||||
|
xpath = f'x:(//*[name()="frame" or name()="iframe"])[{loc_ind_ele}]'
|
||||||
|
return self._ele(xpath)
|
||||||
|
elif str(type(loc_ind_ele)).endswith(".ChromiumFrame'>"):
|
||||||
|
return loc_ind_ele
|
||||||
|
else:
|
||||||
|
raise TypeError('必须传入定位符、iframe序号、ChromiumFrame对象其中之一。')
|
||||||
|
|
||||||
def get_session_storage(self, item=None):
|
def get_session_storage(self, item=None):
|
||||||
"""获取sessionStorage信息,不设置item则获取全部
|
"""获取sessionStorage信息,不设置item则获取全部
|
||||||
:param item: 要获取的项,不设置则返回全部
|
:param item: 要获取的项,不设置则返回全部
|
||||||
|
@ -150,8 +150,8 @@ class ChromiumBase(BasePage):
|
|||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
def s_eles(self, loc_or_str: Union[Tuple[str, str], str]) -> List[Union[SessionElement, str]]: ...
|
||||||
|
|
||||||
def _find_elements(self,
|
def _find_elements(self,
|
||||||
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
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) \
|
||||||
-> Union[ChromiumElement, ChromiumFrame, NoneElement, List[Union[ChromiumElement, ChromiumFrame]]]: ...
|
-> Union[ChromiumElement, ChromiumFrame, NoneElement, List[Union[ChromiumElement, ChromiumFrame]]]: ...
|
||||||
|
|
||||||
def refresh(self, ignore_cache: bool = False) -> None: ...
|
def refresh(self, ignore_cache: bool = False) -> None: ...
|
||||||
@ -166,6 +166,8 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
def remove_ele(self, loc_or_ele: Union[ChromiumElement, ChromiumFrame, str, Tuple[str, str]]) -> None: ...
|
def remove_ele(self, loc_or_ele: Union[ChromiumElement, ChromiumFrame, str, Tuple[str, str]]) -> None: ...
|
||||||
|
|
||||||
|
def get_frame(self, loc_ind_ele: Union[str, int, ChromiumFrame]) -> ChromiumFrame: ...
|
||||||
|
|
||||||
def run_cdp(self, cmd: str, **cmd_args) -> dict: ...
|
def run_cdp(self, cmd: str, **cmd_args) -> dict: ...
|
||||||
|
|
||||||
def run_cdp_loaded(self, cmd: str, **cmd_args) -> dict: ...
|
def run_cdp_loaded(self, cmd: str, **cmd_args) -> dict: ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user