mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-11-29 18:47:34 +08:00
微调
This commit is contained in:
parent
7207f8606a
commit
2092f7a6a3
@ -24,10 +24,14 @@ class DriverElement(DrissionElement):
|
||||
"""driver模式的元素对象,包装了一个WebElement对象,并封装了常用功能"""
|
||||
|
||||
def __init__(self, ele: WebElement, page=None):
|
||||
"""初始化对象 \n
|
||||
:param ele: 被包装的WebElement元素
|
||||
:param page: 元素所在页面
|
||||
"""
|
||||
super().__init__(ele, page)
|
||||
self._select = None
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
attrs = [f"{attr}='{self.attrs[attr]}'" for attr in self.attrs]
|
||||
return f'<DriverElement {self.tag} {" ".join(attrs)}>'
|
||||
|
||||
|
@ -274,9 +274,14 @@ class DriverPage(BasePage):
|
||||
:param url: 新标签页跳转到的网址
|
||||
:return: None
|
||||
"""
|
||||
self.to_tab(-1)
|
||||
self.run_script(f'window.open("{url}");')
|
||||
self.to_tab(-1)
|
||||
try: # selenium4新增功能,须配合新版浏览器
|
||||
self.driver.switch_to.new_window('tab')
|
||||
if url:
|
||||
self.get(url)
|
||||
except:
|
||||
self.to_tab(-1)
|
||||
self.run_script(f'window.open("{url}");')
|
||||
self.to_tab(-1)
|
||||
|
||||
def close_current_tab(self) -> None:
|
||||
"""关闭当前标签页"""
|
||||
|
@ -408,10 +408,10 @@ class MixPage(SessionPage, DriverPage, BasePage):
|
||||
return super().chrome_downloading(path)
|
||||
|
||||
# ----------------MixPage独有函数-----------------------
|
||||
def hide_browser(self):
|
||||
def hide_browser(self) -> None:
|
||||
"""隐藏浏览器窗口"""
|
||||
self.drission.hide_browser()
|
||||
|
||||
def show_browser(self):
|
||||
def show_browser(self) -> None:
|
||||
"""显示浏览器窗口"""
|
||||
self.drission.show_browser()
|
||||
|
@ -19,16 +19,21 @@ class SessionElement(DrissionElement):
|
||||
"""session模式的元素对象,包装了一个lxml的Element对象,并封装了常用功能"""
|
||||
|
||||
def __init__(self, ele: HtmlElement, page=None):
|
||||
"""初始化对象 \n
|
||||
:param ele: 被包装的HtmlElement元素
|
||||
:param page: 元素所在页面对象,如果是从 html 文本生成的元素,则为 None
|
||||
"""
|
||||
super().__init__(ele, page)
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
attrs = [f"{attr}='{self.attrs[attr]}'" for attr in self.attrs]
|
||||
return f'<SessionElement {self.tag} {" ".join(attrs)}>'
|
||||
|
||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str]):
|
||||
"""在内部查找元素 \n
|
||||
例:ele2 = ele1('@id=ele_id') \n
|
||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str], timeout=None):
|
||||
"""在内部查找元素 \n
|
||||
例:ele2 = ele1('@id=ele_id') \n
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:param timeout: 不起实际作用,用于和DriverElement对应,便于无差别调用
|
||||
:return: SessionElement对象或属性、文本
|
||||
"""
|
||||
return self.ele(loc_or_str)
|
||||
|
@ -30,11 +30,12 @@ class SessionPage(BasePage):
|
||||
self._session = session
|
||||
self._response = None
|
||||
|
||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str, SessionElement]) \
|
||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str, SessionElement], timeout=None) \
|
||||
-> Union[SessionElement, List[SessionElement], str]:
|
||||
"""在内部查找元素 \n
|
||||
例:ele2 = ele1('@id=ele_id') \n
|
||||
"""在内部查找元素 \n
|
||||
例:ele2 = ele1('@id=ele_id') \n
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:param timeout: 不起实际作用,用于和DriverElement对应,便于无差别调用
|
||||
:return: SessionElement对象或属性文本
|
||||
"""
|
||||
return self.ele(loc_or_str)
|
||||
|
Loading…
Reference in New Issue
Block a user