mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
取消WebDriverWaitPlus
This commit is contained in:
parent
6a581c2a45
commit
00c9acc173
@ -4,7 +4,6 @@
|
|||||||
@Contact : g1879@qq.com
|
@Contact : g1879@qq.com
|
||||||
@File : common.py
|
@File : common.py
|
||||||
"""
|
"""
|
||||||
import time
|
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from re import split as re_SPLIT
|
from re import split as re_SPLIT
|
||||||
@ -12,9 +11,7 @@ from shutil import rmtree
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from requests_html import Element
|
from requests_html import Element
|
||||||
from selenium.common.exceptions import TimeoutException, InvalidSelectorException
|
|
||||||
from selenium.webdriver.remote.webelement import WebElement
|
from selenium.webdriver.remote.webelement import WebElement
|
||||||
from selenium.webdriver.support.wait import WebDriverWait
|
|
||||||
|
|
||||||
|
|
||||||
class DrissionElement(object):
|
class DrissionElement(object):
|
||||||
@ -76,30 +73,6 @@ class DrissionElement(object):
|
|||||||
# pass
|
# 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:
|
def get_loc_from_str(loc: str) -> tuple:
|
||||||
"""处理元素查找语句 \n
|
"""处理元素查找语句 \n
|
||||||
查找方式:属性、tag name及属性、文本、xpath、css selector \n
|
查找方式:属性、tag name及属性、文本、xpath、css selector \n
|
||||||
|
Loading…
x
Reference in New Issue
Block a user