From 8c02cb99f81aad368565e556bd0a8de01094323e Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 10 Jun 2020 16:50:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=AA=E5=9B=BE=E6=94=B9=E4=B8=BA=E5=BF=85?= =?UTF-8?q?=E9=A1=BB=E4=BC=A0=E5=85=A5=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/driver_element.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/DrissionPage/driver_element.py b/DrissionPage/driver_element.py index b12fc47..11ef825 100644 --- a/DrissionPage/driver_element.py +++ b/DrissionPage/driver_element.py @@ -15,8 +15,7 @@ from selenium.webdriver.support import expected_conditions as ec from selenium.webdriver.support.select import Select from selenium.webdriver.support.wait import WebDriverWait -from .common import DrissionElement, get_loc_from_str, translate_loc_to_xpath -from .config import OptionsManager +from .common import DrissionElement, get_loc_from_str, translate_loc_to_xpath, avoid_duplicate_name class DriverElement(DrissionElement): @@ -201,12 +200,10 @@ class DriverElement(DrissionElement): """元素坐标""" return self.inner_ele.location - def screenshot(self, path: str = None, filename: str = None) -> str: + def screenshot(self, path: str, filename: str = None) -> str: """元素截图""" name = filename or self.tag - path = path or OptionsManager().get_value('paths', 'global_tmp_path') - if not path: - raise IOError('No path specified.') + name = avoid_duplicate_name(path, f'{name}.png') Path(path).mkdir(parents=True, exist_ok=True) # 等待元素加载完成 if self.tag == 'img': @@ -214,7 +211,7 @@ class DriverElement(DrissionElement): '&& arguments[0].naturalWidth > 0' while not self.run_script(js): pass - img_path = f'{path}\\{name}.png' + img_path = f'{path}\\{name}' self.inner_ele.screenshot(img_path) return img_path