mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
浏览器页面对象增加is_alive属性;下拉列表增加by_loc选择方式
This commit is contained in:
parent
ac52c699a5
commit
aaab200c5e
@ -244,6 +244,15 @@ class ChromiumBase(BasePage):
|
|||||||
"""返回页面是否正在加载状态"""
|
"""返回页面是否正在加载状态"""
|
||||||
return self._is_loading
|
return self._is_loading
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_alive(self):
|
||||||
|
"""返回页面对象是否仍然可用"""
|
||||||
|
try:
|
||||||
|
self.run_cdp('Page.getLayoutMetrics')
|
||||||
|
return True
|
||||||
|
except TabClosedError:
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
"""返回当前页面title"""
|
"""返回当前页面title"""
|
||||||
|
@ -80,6 +80,9 @@ class ChromiumBase(BasePage):
|
|||||||
@property
|
@property
|
||||||
def is_loading(self) -> bool: ...
|
def is_loading(self) -> bool: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_alive(self) -> bool: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self) -> str: ...
|
def url(self) -> str: ...
|
||||||
|
|
||||||
|
@ -1833,8 +1833,7 @@ class ChromiumSelect(object):
|
|||||||
@property
|
@property
|
||||||
def is_multi(self):
|
def is_multi(self):
|
||||||
"""返回是否多选表单"""
|
"""返回是否多选表单"""
|
||||||
multi = self._ele.attr('multiple')
|
return self._ele.attr('multiple') is not None
|
||||||
return multi and multi.lower() != "false"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def options(self):
|
def options(self):
|
||||||
@ -1891,6 +1890,25 @@ class ChromiumSelect(object):
|
|||||||
timeout = timeout if timeout is not None else self._ele.page.timeout
|
timeout = timeout if timeout is not None else self._ele.page.timeout
|
||||||
return self._select(index, 'index', False, timeout)
|
return self._select(index, 'index', False, timeout)
|
||||||
|
|
||||||
|
def by_loc(self, loc, timeout=None):
|
||||||
|
"""用定位符选择要选择的项
|
||||||
|
:param loc: 定位符
|
||||||
|
:param timeout: 超时时间
|
||||||
|
:return: 是否选择成功
|
||||||
|
"""
|
||||||
|
eles = self._ele.eles(loc, timeout)
|
||||||
|
if not eles:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self.is_multi:
|
||||||
|
for ele in eles:
|
||||||
|
ele.run_js(f'this.selected=true;')
|
||||||
|
return True
|
||||||
|
|
||||||
|
eles[0].run_js(f'this.selected=true;')
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def cancel_by_text(self, text, timeout=None):
|
def cancel_by_text(self, text, timeout=None):
|
||||||
"""此方法用于根据text值取消选择项。当元素是多选列表时,可以接收list或tuple
|
"""此方法用于根据text值取消选择项。当元素是多选列表时,可以接收list或tuple
|
||||||
:param text: 文本,传入list或tuple可取消多项
|
:param text: 文本,传入list或tuple可取消多项
|
||||||
|
@ -511,6 +511,8 @@ class ChromiumSelect(object):
|
|||||||
|
|
||||||
def by_index(self, index: Union[int, list, tuple], timeout: float = None) -> bool: ...
|
def by_index(self, index: Union[int, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
|
def by_loc(self, loc: Union[str, Tuple[str, str]], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def cancel_by_text(self, text: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
def cancel_by_text(self, text: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
|
||||||
def cancel_by_value(self, value: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
def cancel_by_value(self, value: Union[str, list, tuple], timeout: float = None) -> bool: ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user