mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
改进new_tab(),未完成
This commit is contained in:
parent
231cd0724b
commit
c26a3d78b2
@ -9,3 +9,6 @@
|
|||||||
2. 请附上代码和报错信息(如有)
|
2. 请附上代码和报错信息(如有)
|
||||||
3. DrissionPage、浏览器、python版本号是多少?
|
3. DrissionPage、浏览器、python版本号是多少?
|
||||||
4. 有什么意见建议?
|
4. 有什么意见建议?
|
||||||
|
|
||||||
|
请在下方写正文,不要把内容插入到上面的问题中。
|
||||||
|
---
|
@ -26,7 +26,7 @@ from .._pages.chromium_tab import ChromiumTab, MixTab
|
|||||||
from .._units.downloader import DownloadManager
|
from .._units.downloader import DownloadManager
|
||||||
from .._units.setter import BrowserSetter
|
from .._units.setter import BrowserSetter
|
||||||
from .._units.waiter import BrowserWaiter
|
from .._units.waiter import BrowserWaiter
|
||||||
from ..errors import BrowserConnectError
|
from ..errors import BrowserConnectError, CDPError
|
||||||
from ..errors import PageDisconnectedError
|
from ..errors import PageDisconnectedError
|
||||||
|
|
||||||
__ERROR__ = 'error'
|
__ERROR__ = 'error'
|
||||||
@ -219,7 +219,14 @@ class Browser(object):
|
|||||||
if tab:
|
if tab:
|
||||||
kwargs['browserContextId'] = tab
|
kwargs['browserContextId'] = tab
|
||||||
|
|
||||||
|
try:
|
||||||
tab = self._run_cdp('Target.createTarget', **kwargs)['targetId']
|
tab = self._run_cdp('Target.createTarget', **kwargs)['targetId']
|
||||||
|
except CDPError:
|
||||||
|
url = url or 'https://#'
|
||||||
|
tab = self.get_tab().add_ele(('a', {'href': url,
|
||||||
|
'target': '_blank'})).click.for_new_tab(by_js=True)
|
||||||
|
return tab
|
||||||
|
|
||||||
while tab not in self._drivers:
|
while tab not in self._drivers:
|
||||||
sleep(.1)
|
sleep(.1)
|
||||||
tab = obj(self, tab)
|
tab = obj(self, tab)
|
||||||
|
@ -11,7 +11,7 @@ from typing import List, Optional, Set, Dict, Union, Tuple
|
|||||||
from .driver import BrowserDriver, Driver
|
from .driver import BrowserDriver, Driver
|
||||||
from .._configs.chromium_options import ChromiumOptions
|
from .._configs.chromium_options import ChromiumOptions
|
||||||
from .._configs.session_options import SessionOptions
|
from .._configs.session_options import SessionOptions
|
||||||
from .._functions.web import CookiesList
|
from .._functions.cookies import CookiesList
|
||||||
from .._pages.chromium_base import Timeout
|
from .._pages.chromium_base import Timeout
|
||||||
from .._pages.chromium_tab import ChromiumTab, MixTab
|
from .._pages.chromium_tab import ChromiumTab, MixTab
|
||||||
from .._units.downloader import DownloadManager
|
from .._units.downloader import DownloadManager
|
||||||
|
@ -1185,6 +1185,7 @@ def close_privacy_dialog(page, tid):
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
print('ooo')
|
||||||
driver = page.browser._get_driver(tid)
|
driver = page.browser._get_driver(tid)
|
||||||
driver.run('Runtime.enable')
|
driver.run('Runtime.enable')
|
||||||
driver.run('DOM.enable')
|
driver.run('DOM.enable')
|
||||||
|
@ -14,8 +14,8 @@ from .._base.browser import Browser
|
|||||||
from .._base.driver import Driver
|
from .._base.driver import Driver
|
||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._elements.session_element import SessionElement
|
from .._elements.session_element import SessionElement
|
||||||
|
from .._functions.cookies import CookiesList
|
||||||
from .._functions.elements import SessionElementsList, ChromiumElementsList
|
from .._functions.elements import SessionElementsList, ChromiumElementsList
|
||||||
from .._functions.web import CookiesList
|
|
||||||
from .._pages.chromium_frame import ChromiumFrame
|
from .._pages.chromium_frame import ChromiumFrame
|
||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._units.actions import Actions
|
from .._units.actions import Actions
|
||||||
|
@ -170,7 +170,6 @@ class ChromiumPage(ChromiumBase):
|
|||||||
|
|
||||||
def _on_disconnect(self):
|
def _on_disconnect(self):
|
||||||
"""浏览器退出时执行"""
|
"""浏览器退出时执行"""
|
||||||
print('kkk')
|
|
||||||
ChromiumPage._PAGES.pop(self._browser.id, None)
|
ChromiumPage._PAGES.pop(self._browser.id, None)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
@License : BSD 3-Clause.
|
@License : BSD 3-Clause.
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from threading import Lock
|
|
||||||
from typing import Union, Tuple, List, Optional
|
from typing import Union, Tuple, List, Optional
|
||||||
|
|
||||||
from .._base.browser import Browser
|
from .._base.browser import Browser
|
||||||
|
@ -16,8 +16,8 @@ from .session_page import SessionPage
|
|||||||
from .._base.browser import Browser
|
from .._base.browser import Browser
|
||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._elements.session_element import SessionElement
|
from .._elements.session_element import SessionElement
|
||||||
|
from .._functions.cookies import CookiesList
|
||||||
from .._functions.elements import SessionElementsList, ChromiumElementsList
|
from .._functions.elements import SessionElementsList, ChromiumElementsList
|
||||||
from .._functions.web import CookiesList
|
|
||||||
from .._units.rect import TabRect
|
from .._units.rect import TabRect
|
||||||
from .._units.setter import TabSetter, WebPageTabSetter
|
from .._units.setter import TabSetter, WebPageTabSetter
|
||||||
from .._units.waiter import TabWaiter
|
from .._units.waiter import TabWaiter
|
||||||
|
@ -14,8 +14,8 @@ from requests.structures import CaseInsensitiveDict
|
|||||||
from .._base.base import BasePage
|
from .._base.base import BasePage
|
||||||
from .._configs.session_options import SessionOptions
|
from .._configs.session_options import SessionOptions
|
||||||
from .._elements.session_element import SessionElement
|
from .._elements.session_element import SessionElement
|
||||||
|
from .._functions.cookies import CookiesList
|
||||||
from .._functions.elements import SessionElementsList
|
from .._functions.elements import SessionElementsList
|
||||||
from .._functions.web import CookiesList
|
|
||||||
from .._units.setter import SessionPageSetter
|
from .._units.setter import SessionPageSetter
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
"""
|
"""
|
||||||
return super().__new__(cls, chromium_options)
|
return super().__new__(cls, chromium_options)
|
||||||
|
|
||||||
def __init__(self, mode='d', timeout=None, chromium_options=None, session_or_options=None, driver_or_options=None):
|
def __init__(self, mode='d', timeout=None, chromium_options=None, session_or_options=None):
|
||||||
"""初始化函数
|
"""初始化函数
|
||||||
:param mode: 'd' 或 's',即driver模式和session模式
|
:param mode: 'd' 或 's',即driver模式和session模式
|
||||||
:param timeout: 超时时间(秒),d模式时为寻找元素时间,s模式时为连接时间,默认10秒
|
:param timeout: 超时时间(秒),d模式时为寻找元素时间,s模式时为连接时间,默认10秒
|
||||||
|
@ -166,7 +166,7 @@ class Clicker(object):
|
|||||||
elif not self._ele.tab._browser._dl_mgr._running:
|
elif not self._ele.tab._browser._dl_mgr._running:
|
||||||
self._ele.tab._browser.set.download_path('.')
|
self._ele.tab._browser.set.download_path('.')
|
||||||
|
|
||||||
obj = self._ele.tab._browser if new_tab else self._ele.owner.tab
|
obj = self._ele.tab._browser if new_tab else self._ele.owner._tab
|
||||||
if rename or suffix:
|
if rename or suffix:
|
||||||
obj.set.download_file_name(rename, suffix)
|
obj.set.download_file_name(rename, suffix)
|
||||||
|
|
||||||
|
@ -101,9 +101,7 @@ class ElementRect(object):
|
|||||||
:param quad: 方框类型,margin border padding
|
:param quad: 方框类型,margin border padding
|
||||||
:return: 四个角坐标
|
:return: 四个角坐标
|
||||||
"""
|
"""
|
||||||
return self._ele.owner._run_cdp('DOM.getBoxModel', backendNodeId=self._ele._backend_id,
|
return self._ele.owner._run_cdp('DOM.getBoxModel', backendNodeId=self._ele._backend_id)['model'][quad]
|
||||||
# nodeId=self._ele._node_id, objectId=self._ele._obj_id
|
|
||||||
)['model'][quad]
|
|
||||||
|
|
||||||
def _get_page_coord(self, x, y):
|
def _get_page_coord(self, x, y):
|
||||||
"""根据视口坐标获取绝对坐标"""
|
"""根据视口坐标获取绝对坐标"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user