3.1.3ChromiumBase的title、url、html等待加载结束才返回;wait_loading()默认使用页面timeout属性

This commit is contained in:
g1879 2023-02-02 23:35:57 +08:00
parent f3155df7a9
commit b5892c622b
3 changed files with 8 additions and 4 deletions

View File

@ -198,6 +198,7 @@ class ChromiumBase(BasePage):
@property
def title(self):
"""返回当前页面title"""
self._wait_loaded()
return self._tab_obj.Target.getTargetInfo(targetId=self.tab_id)['targetInfo']['title']
@property
@ -225,11 +226,13 @@ class ChromiumBase(BasePage):
@property
def url(self):
"""返回当前页面url"""
self._wait_loaded()
return self._tab_obj.Target.getTargetInfo(targetId=self.tab_id)['targetInfo']['url']
@property
def html(self):
"""返回当前页面html文本"""
self._wait_loaded()
return self._wait_driver.DOM.getOuterHTML(objectId=self._root_id)['outerHTML']
@property
@ -338,13 +341,13 @@ class ChromiumBase(BasePage):
timeout=timeout)
return self._url_available
def wait_loading(self, timeout=1):
def wait_loading(self, timeout=None):
"""阻塞程序,等待页面进入加载状态
:param timeout: 超时时间
:return: 等待结束时是否进入加载状态
"""
if timeout:
timeout = 2 if timeout is True else timeout
if timeout != 0:
timeout = self.timeout if timeout in (None, True) else timeout
end_time = perf_counter() + timeout
while perf_counter() < end_time:
if self.is_loading:

View File

@ -318,6 +318,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
:param mode: 模式字符串
:param go: 是否跳转到原模式的url
:param copy_cookies: 是否复制cookies到目标模式
:return: None
"""
if mode is not None and mode.lower() == self._mode:
return

View File

@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup(
name="DrissionPage",
version="3.1.2",
version="3.1.3",
author="g1879",
author_email="g1879@qq.com",
description="A module that integrates selenium and requests session, encapsulates common page operations.",