优化截图功能

This commit is contained in:
g1879 2023-10-10 09:41:26 +08:00
parent 9690a57502
commit fa6bc08b5b
2 changed files with 3 additions and 3 deletions

View File

@ -501,7 +501,7 @@ class ChromiumElement(DrissionElement):
return str(path)
def get_screenshot(self, path=None, name=None, as_bytes=None, as_base64=None, scroll_to_center=False):
def get_screenshot(self, path=None, name=None, as_bytes=None, as_base64=None, scroll_to_center=True):
"""对当前元素截图,可保存到文件,或以字节方式返回
:param path: 文件保存路径
:param name: 完整文件名后缀可选 'jpg','jpeg','png','webp'
@ -516,7 +516,6 @@ class ChromiumElement(DrissionElement):
end_time = perf_counter() + self.page.timeout
while not self.run_js(js) and perf_counter() < end_time:
sleep(.1)
if scroll_to_center:
self.scroll.to_see(center=True)
@ -526,6 +525,7 @@ class ChromiumElement(DrissionElement):
right_bottom = (left + width, top + height)
if not name:
name = f'{self.tag}.jpg'
return self.page._get_screenshot(path, name, as_bytes=as_bytes, as_base64=as_base64, full_page=False,
left_top=left_top, right_bottom=right_bottom, ele=self)

View File

@ -183,7 +183,7 @@ class ChromiumElement(DrissionElement):
def save(self, path: [str, bool] = None, name: str = None, timeout: float = None) -> str: ...
def get_screenshot(self, path: [str, Path] = None, name: str = None, as_bytes: [bool, str] = None,
as_base64: [bool, str] = None, scroll_to_center: bool = False) -> Union[str, bytes]: ...
as_base64: [bool, str] = None, scroll_to_center: bool = True) -> Union[str, bytes]: ...
def input(self, vals: Any, clear: bool = True, by_js: bool = False) -> None: ...