From 00c9acc1738cce8ac5b0c17da353406e01b73623 Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 3 Nov 2020 11:40:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88WebDriverWaitPlus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/common.py | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/DrissionPage/common.py b/DrissionPage/common.py index 579e1a8..d2a1f66 100644 --- a/DrissionPage/common.py +++ b/DrissionPage/common.py @@ -4,7 +4,6 @@ @Contact : g1879@qq.com @File : common.py """ -import time from abc import abstractmethod from pathlib import Path from re import split as re_SPLIT @@ -12,9 +11,7 @@ from shutil import rmtree from typing import Union from requests_html import Element -from selenium.common.exceptions import TimeoutException, InvalidSelectorException from selenium.webdriver.remote.webelement import WebElement -from selenium.webdriver.support.wait import WebDriverWait class DrissionElement(object): @@ -76,30 +73,6 @@ class DrissionElement(object): # pass -class WebDriverWaitPlus(WebDriverWait): - """重写until方法,使其在接收到InvalidSelectorException异常时跳出""" - - def until(self, method, message=''): - screen = None - stacktrace = None - - end_time = time.time() + self._timeout - while True: - try: - value = method(self._driver) - if value: - return value - except self._ignored_exceptions as exc: - if isinstance(exc, InvalidSelectorException): - raise exc - screen = getattr(exc, 'screen', None) - stacktrace = getattr(exc, 'stacktrace', None) - time.sleep(self._poll) - if time.time() > end_time: - break - raise TimeoutException(message, screen, stacktrace) - - def get_loc_from_str(loc: str) -> tuple: """处理元素查找语句 \n 查找方式:属性、tag name及属性、文本、xpath、css selector \n