3.2.26find_tabs()增加special参数;修复标签页对象内元素无法获取屏幕坐标问题

This commit is contained in:
g1879 2023-04-07 20:07:59 +08:00
parent 9e509ec256
commit 07d32a1f87
5 changed files with 21 additions and 9 deletions

View File

@ -194,19 +194,22 @@ class ChromiumPage(ChromiumBase):
tab_id = tab_id or self.tab_id tab_id = tab_id or self.tab_id
return ChromiumTab(self, tab_id) return ChromiumTab(self, tab_id)
def find_tabs(self, text, by_title=True, by_url=None): def find_tabs(self, text=None, by_title=True, by_url=None, special=False):
"""查找符合条件的tab返回它们的id组成的列表 """查找符合条件的tab返回它们的id组成的列表
:param text: 查询条件 :param text: 查询条件
:param by_title: 是否匹配title :param by_title: 是否匹配title
:param by_url: 是否匹配url :param by_url: 是否匹配url
:param special: 是否匹配特殊tab如打印页
:return: tab id组成的列表 :return: tab id组成的列表
""" """
if not (by_title or by_url):
return self.tabs
tabs = self._control_session.get(f'http://{self.address}/json').json() # 不要改用cdp tabs = self._control_session.get(f'http://{self.address}/json').json() # 不要改用cdp
return [i['id'] for i in tabs if i['type'] == 'page' and ((by_url and text in i['url']) or if text is None or not (by_title or by_url):
(by_title and text in i['title']))] return [i['id'] for i in tabs if (not special and i['type'] == 'page')
or (special and i['type'] not in ('page', 'iframe'))]
return [i['id'] for i in tabs if ((not special and i['type'] == 'page')
or (special and i['type'] not in ('page', 'iframe')))
and ((by_url and text in i['url']) or (by_title and text in i['title']))]
def new_tab(self, url=None, switch_to=True): def new_tab(self, url=None, switch_to=True):
"""新建一个标签页,该标签页在最后面 """新建一个标签页,该标签页在最后面

View File

@ -81,7 +81,8 @@ class ChromiumPage(ChromiumBase):
def get_tab(self, tab_id: str = None) -> ChromiumTab: ... def get_tab(self, tab_id: str = None) -> ChromiumTab: ...
def find_tabs(self, text: str, by_title: bool = True, by_url: bool = None) -> List[str]: ... def find_tabs(self, text: str = None, by_title: bool = True, by_url: bool = None,
special: bool = False) -> List[str]: ...
def new_tab(self, url: str = None, switch_to: bool = True) -> str: ... def new_tab(self, url: str = None, switch_to: bool = True) -> str: ...

View File

@ -28,6 +28,11 @@ class ChromiumTab(ChromiumBase):
self.retry_interval = self.page.retry_interval self.retry_interval = self.page.retry_interval
self._page_load_strategy = self.page.page_load_strategy self._page_load_strategy = self.page.page_load_strategy
@property
def rect(self):
"""返回获取窗口坐标和大小的对象"""
return self.page.rect
class WebPageTab(SessionPage, ChromiumTab): class WebPageTab(SessionPage, ChromiumTab):
def __init__(self, page, tab_id): def __init__(self, page, tab_id):

View File

@ -11,7 +11,7 @@ from requests import Session, Response
from .chromium_base import ChromiumBase, ChromiumBaseSetter from .chromium_base import ChromiumBase, ChromiumBaseSetter
from .chromium_element import ChromiumElement from .chromium_element import ChromiumElement
from .chromium_frame import ChromiumFrame from .chromium_frame import ChromiumFrame
from .chromium_page import ChromiumPage from .chromium_page import ChromiumPage, ChromiumTabRect
from .session_element import SessionElement from .session_element import SessionElement
from .session_page import SessionPage, SessionPageSetter, DownloadSetter from .session_page import SessionPage, SessionPageSetter, DownloadSetter
from .web_page import WebPage from .web_page import WebPage
@ -24,6 +24,9 @@ class ChromiumTab(ChromiumBase):
def _set_runtime_settings(self) -> None: ... def _set_runtime_settings(self) -> None: ...
@property
def rect(self) -> ChromiumTabRect: ...
class WebPageTab(SessionPage, ChromiumTab): class WebPageTab(SessionPage, ChromiumTab):
def __init__(self, page: WebPage, tab_id: str): def __init__(self, page: WebPage, tab_id: str):

View File

@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup( setup(
name="DrissionPage", name="DrissionPage",
version="3.2.25", version="3.2.26",
author="g1879", author="g1879",
author_email="g1879@qq.com", author_email="g1879@qq.com",
description="Python based web automation tool. It can control the browser and send and receive data packets.", description="Python based web automation tool. It can control the browser and send and receive data packets.",