修复没有page类在title时会出现的问题

This commit is contained in:
g1879 2021-08-13 17:38:34 +08:00
parent 346b88ba41
commit 98b02f3452
5 changed files with 10 additions and 20 deletions

View File

@ -225,6 +225,12 @@ class BasePage(BaseParser):
self.retry_interval = 2 self.retry_interval = 2
self._url_available = None self._url_available = None
@property
def title(self) -> Union[str, None]:
"""返回网页title"""
ele = self('t:title')
return ele.text if ele else None
@property @property
def timeout(self) -> float: def timeout(self) -> float:
"""返回查找元素时等待的秒数""" """返回查找元素时等待的秒数"""
@ -253,10 +259,6 @@ class BasePage(BaseParser):
def url(self): def url(self):
return return
@property
def title(self):
return
@property @property
def html(self): def html(self):
return return

View File

@ -331,7 +331,7 @@ class DriverElement(DrissionElement):
"""输入文本或组合键,可用于所有场合 \n """输入文本或组合键,可用于所有场合 \n
:param vals: 文本值或按键组合 :param vals: 文本值或按键组合
:param clear: 输入前是否清空文本框 :param clear: 输入前是否清空文本框
:return: 是否输入成功 :return: None
""" """
if clear: if clear:
self.clear() self.clear()
@ -342,7 +342,7 @@ class DriverElement(DrissionElement):
"""专门用于输入文本框,解决文本框有时输入失效的问题 \n """专门用于输入文本框,解决文本框有时输入失效的问题 \n
:param txt: 文本值 :param txt: 文本值
:param clear: 输入前是否清空文本框 :param clear: 输入前是否清空文本框
:return: 是否输入成功 :return: None
""" """
enter = '\n' if txt.endswith('\n') else None enter = '\n' if txt.endswith('\n') else None
full_txt = txt if clear else f'{self.attr("value")}{txt}' full_txt = txt if clear else f'{self.attr("value")}{txt}'

View File

@ -51,11 +51,6 @@ class DriverPage(BasePage):
else: else:
return self.driver.current_url return self.driver.current_url
@property
def title(self) -> str:
"""返回网页title"""
return self.driver.title
@property @property
def html(self) -> str: def html(self) -> str:
"""返回页面html文本""" """返回页面html文本"""

View File

@ -49,11 +49,6 @@ class SessionPage(BasePage):
"""返回当前访问url""" """返回当前访问url"""
return self._url return self._url
@property
def title(self) -> str:
"""返回网页title"""
return self.ele('tag:title').text
@property @property
def html(self) -> str: def html(self) -> str:
"""返回页面html文本""" """返回页面html文本"""

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
from setuptools import setup, find_packages from setuptools import setup, find_packages
with open("README.md", "r", encoding='utf-8') as fh: with open("README.md", "r", encoding='utf-8') as fh:
@ -8,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup( setup(
name="DrissionPage", name="DrissionPage",
version="1.9.3", version="1.11.0 beta",
author="g1879", author="g1879",
author_email="g1879@qq.com", author_email="g1879@qq.com",
description="A module that integrates selenium and requests session, encapsulates common page operations.", description="A module that integrates selenium and requests session, encapsulates common page operations.",
@ -16,7 +14,7 @@ setup(
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
license="BSD", license="BSD",
keywords="DrissionPage", keywords="DrissionPage",
url="https://github.com/g1879/DrissionPage", url="https://gitee.com/g1879/DrissionPage",
include_package_data=True, include_package_data=True,
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=[