mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
适应最新版浏览器的修改,tabs不包含F12的窗口
This commit is contained in:
parent
2a0fa73f9d
commit
2ddb7aff95
@ -80,13 +80,13 @@ class Browser(object):
|
||||
def tabs_count(self):
|
||||
"""返回标签页数量"""
|
||||
j = self.run_cdp('Target.getTargets')['targetInfos'] # 不要改用get,避免卡死
|
||||
return len([i for i in j if i['type'] == 'page'])
|
||||
return len([i for i in j if i['type'] == 'page' and not i['url'].startswith('devtools://')])
|
||||
|
||||
@property
|
||||
def tabs(self):
|
||||
"""返回所有标签页id组成的列表"""
|
||||
j = self._driver.get(f'http://{self.address}/json').json() # 不要改用cdp,因为顺序不对
|
||||
return [i['id'] for i in j if i['type'] == 'page']
|
||||
return [i['id'] for i in j if i['type'] == 'page' and not i['url'].startswith('devtools://')]
|
||||
|
||||
@property
|
||||
def process_id(self):
|
||||
|
@ -10,8 +10,6 @@ from re import findall
|
||||
from threading import Thread
|
||||
from time import perf_counter, sleep
|
||||
|
||||
from requests import get
|
||||
|
||||
from .._base.base import BasePage
|
||||
from .._base.chromium_driver import ChromiumDriver
|
||||
from .._commons.constants import ERROR, NoneElement
|
||||
@ -25,8 +23,8 @@ from .._units.network_listener import NetworkListener
|
||||
from .._units.screencast import Screencast
|
||||
from .._units.setter import ChromiumBaseSetter
|
||||
from .._units.waiter import ChromiumBaseWaiter
|
||||
from ..errors import (ContextLossError, ElementLossError, CDPError, TabClosedError, NoRectError, BrowserConnectError,
|
||||
AlertExistsError, GetDocumentError)
|
||||
from ..errors import (ContextLossError, ElementLossError, CDPError, TabClosedError, NoRectError, AlertExistsError,
|
||||
GetDocumentError)
|
||||
|
||||
|
||||
class ChromiumBase(BasePage):
|
||||
@ -84,11 +82,7 @@ class ChromiumBase(BasePage):
|
||||
self._scroll = None
|
||||
|
||||
if not tab_id:
|
||||
json = get(f'http://{self.address}/json', headers={'Connection': 'close'}).json()
|
||||
tab_id = [i['id'] for i in json if i['type'] == 'page']
|
||||
if not tab_id:
|
||||
raise BrowserConnectError('浏览器连接失败,可能是浏览器版本原因。')
|
||||
tab_id = tab_id[0]
|
||||
tab_id = self.browser.tabs[0]
|
||||
|
||||
self._driver_init(tab_id)
|
||||
if self.ready_state == 'complete' and self._ready_state is None:
|
||||
|
@ -32,7 +32,7 @@ class Clicker(object):
|
||||
:param timeout: 模拟点击的超时时间,等待元素可见、不被遮挡、进入视口
|
||||
:return: 是否点击成功
|
||||
"""
|
||||
if not by_js:
|
||||
if not by_js: # 模拟点击
|
||||
try:
|
||||
self._ele.scroll.to_see()
|
||||
can_click = False
|
||||
@ -65,7 +65,6 @@ class Clicker(object):
|
||||
return True
|
||||
if Settings.raise_when_click_failed:
|
||||
raise CanNotClickError
|
||||
|
||||
return False
|
||||
|
||||
def right(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user