From 756e2e6e4876a03fc30eeb4d4f423085ba6cb49f Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 25 May 2020 23:50:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=8F=AA=E7=94=A8=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E5=AD=98=E6=94=BEself.=5Fdriver=5Foptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/drission.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/DrissionPage/drission.py b/DrissionPage/drission.py index bff07b5..3356405 100644 --- a/DrissionPage/drission.py +++ b/DrissionPage/drission.py @@ -15,7 +15,7 @@ from selenium.common.exceptions import WebDriverException from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.webdriver import WebDriver -from .config import _dict_to_chrome_options, OptionsManager +from .config import _dict_to_chrome_options, OptionsManager, _chrome_options_to_dict class Drission(object): @@ -33,7 +33,7 @@ class Drission(object): self._driver = None om = OptionsManager(ini_path) self._session_options = session_options or om.get_option('session_options') - self._driver_options = driver_options or om.get_option('chrome_options') + self._driver_options = _chrome_options_to_dict(driver_options) or om.get_option('chrome_options') if driver_path: self._driver_path = driver_path @@ -59,14 +59,7 @@ class Drission(object): def driver(self): """获取WebDriver对象,按传入配置信息初始化""" if self._driver is None: - if isinstance(self._driver_options, Options): - options = self._driver_options - if options.debugger_address: - # 因同时设置调试浏览器和其他配置会导致异常,故新建一个对象 - debugger_address = options.debugger_address - options = webdriver.ChromeOptions() - options.debugger_address = debugger_address - elif isinstance(self._driver_options, dict): + if isinstance(self._driver_options, dict): options = _dict_to_chrome_options(self._driver_options) else: raise KeyError('Driver options invalid') @@ -84,6 +77,10 @@ class Drission(object): return self._driver + @property + def driver_options(self) -> dict: + return self._driver_options + @property def session_options(self) -> dict: return self._session_options