修复select.by_index()报错;删除弃用的方法和属性

This commit is contained in:
g1879 2023-04-12 19:21:28 +08:00
parent 07d32a1f87
commit edf6896045
7 changed files with 1 additions and 400 deletions

View File

@ -10,7 +10,6 @@ from pathlib import Path
from re import search
from threading import Thread
from time import perf_counter, sleep, time
from warnings import warn
from FlowViewer.listener import ResponseData
from requests import Session
@ -857,82 +856,6 @@ class ChromiumBase(BasePage):
f.write(png)
return str(path.absolute())
# ------------------准备废弃----------------------
def wait_loading(self, timeout=None):
"""阻塞程序,等待页面进入加载状态
:param timeout: 超时时间
:return: 等待结束时是否进入加载状态
"""
warn("wait_loading()方法即将弃用请用wait.load_start()方法代替。", DeprecationWarning)
return self.wait.load_start(timeout)
def scroll_to_see(self, loc_or_ele):
"""滚动页面直到元素可见
:param loc_or_ele: 元素的定位信息可以是loc元组或查询字符串详见ele函数注释
:return: None
"""
warn("scroll_to_see()方法即将弃用请用scroll.to_see()方法代替。", DeprecationWarning)
self.scroll.to_see(loc_or_ele)
def set_timeouts(self, implicit=None, page_load=None, script=None):
"""设置超时时间,单位为秒
:param implicit: 查找元素超时时间
:param page_load: 页面加载超时时间
:param script: 脚本运行超时时间
:return: None
"""
warn("set_timeouts()方法即将弃用请用set.timeouts()方法代替。", DeprecationWarning)
self.set.timeouts(implicit, page_load, script)
def set_session_storage(self, item, value):
"""设置或删除某项sessionStorage信息
:param item: 要设置的项
:param value: 项的值设置为False时删除该项
:return: None
"""
warn("set_session_storage()方法即将弃用请用set.session_storage()方法代替。", DeprecationWarning)
return self.set.session_storage(item, value)
def set_local_storage(self, item, value):
"""设置或删除某项localStorage信息
:param item: 要设置的项
:param value: 项的值设置为False时删除该项
:return: None
"""
warn("set_local_storage()方法即将弃用请用set.local_storage()方法代替。", DeprecationWarning)
return self.set.local_storage(item, value)
def set_user_agent(self, ua, platform=None):
"""为当前tab设置user agent只在当前tab有效
:param ua: user agent字符串
:param platform: platform字符串
:return: None
"""
warn("set_user_agent()方法即将弃用请用set.user_agent()方法代替。", DeprecationWarning)
self.set.user_agent(ua, platform)
def set_cookies(self, cookies):
"""设置cookies值
:param cookies: cookies信息
:return: None
"""
warn("set_cookies()方法即将弃用请用set.cookies()方法代替。", DeprecationWarning)
self.set.cookies(cookies)
def set_headers(self, headers: dict) -> None:
"""设置固定发送的headers
:param headers: dict格式的headers数据
:return: None
"""
warn("set_headers()方法即将弃用请用set.headers()方法代替。", DeprecationWarning)
self.set.headers(headers)
@property
def set_page_load_strategy(self):
"""返回用于设置页面加载策略的对象"""
warn("set_page_load_strategy()方法即将弃用请用set.load_strategy.xxxx()方法代替。", DeprecationWarning)
return self.set.load_strategy
class ChromiumBaseSetter(object):
def __init__(self, page):

View File

@ -7,7 +7,6 @@ from os import sep
from os.path import basename
from pathlib import Path
from time import perf_counter, sleep
from warnings import warn
from .base import DrissionElement, BaseElement
from .commons.constants import FRAME_ELEMENT, NoneElement, Settings
@ -715,147 +714,6 @@ class ChromiumElement(DrissionElement):
files = [str(Path(i).absolute()) for i in files]
self.page.run_cdp('DOM.setFileInputFiles', files=files, backendNodeId=self._backend_id)
# ---------------准备废弃-----------------
def click_at(self, offset_x=None, offset_y=None, button='left'):
"""带偏移量点击本元素相对于左上角坐标。不传入x或y值时点击元素左上角可接受点击的点
:param offset_x: 相对元素左上角坐标的x轴偏移量
:param offset_y: 相对元素左上角坐标的y轴偏移量
:param button: 左键还是右键
:return: None
"""
warn("click_at()方法即将弃用请用click.left_at()方法代替。", DeprecationWarning)
self.click.at(offset_x, offset_y, 'left')
def r_click(self):
"""右键单击"""
warn("r_click()方法即将弃用请用click.right()方法代替。", DeprecationWarning)
self.click.right()
def r_click_at(self, offset_x=None, offset_y=None):
"""带偏移量右键单击本元素相对于左上角坐标。不传入x或y值时点击元素中点
:param offset_x: 相对元素左上角坐标的x轴偏移量
:param offset_y: 相对元素左上角坐标的y轴偏移量
:return: None
"""
warn("r_click_at()方法即将弃用请用click.right_at()方法代替。", DeprecationWarning)
self.click.at(offset_x, offset_y, 'right')
def m_click(self):
"""中键单击"""
warn("m_click()方法即将弃用请用click.middle()方法代替。", DeprecationWarning)
self.click.middle()
@property
def client_location(self):
"""返回元素左上角在视口中的坐标"""
warn("client_location属性即将弃用请用locations.viewport_location代替。", DeprecationWarning)
return self.locations.viewport_location
@property
def client_midpoint(self):
"""返回元素中间点在视口中的坐标"""
warn("client_midpoint属性即将弃用请用locations.client_midpoint代替。", DeprecationWarning)
return self.locations.viewport_midpoint
@property
def midpoint(self):
"""返回元素中间点的绝对坐标"""
warn("midpoint属性即将弃用请用locations.midpoint代替。", DeprecationWarning)
return self.locations.midpoint
def set_attr(self, attr, value):
"""设置元素attribute属性
:param attr: 属性名
:param value: 属性值
:return: None
"""
warn("set_attr()方法即将弃用请用set.attr()方法代替。", DeprecationWarning)
self.set.attr(attr, value)
def set_prop(self, prop, value):
"""设置元素property属性
:param prop: 属性名
:param value: 属性值
:return: None
"""
warn("set_prop()方法即将弃用请用set.prop()方法代替。", DeprecationWarning)
self.set.prop(prop, value)
def set_innerHTML(self, html):
"""设置元素innerHTML
:param html: html文本
:return: None
"""
warn("set_innerHTML()方法即将弃用请用set.innerHTML()方法代替。", DeprecationWarning)
self.set.innerHTML(html)
@property
def is_selected(self):
"""返回元素是否被选择"""
warn("is_selected属性即将弃用请用states.is_selected属性代替。", DeprecationWarning)
return self.states.is_selected
@property
def is_displayed(self):
"""返回元素是否显示"""
warn("is_displayed属性即将弃用请用states.is_displayed属性代替。", DeprecationWarning)
return self.states.is_displayed
@property
def is_enabled(self):
"""返回元素是否可用"""
warn("is_enabled属性即将弃用请用states.is_enabled属性代替。", DeprecationWarning)
return self.states.is_enabled
@property
def is_alive(self):
"""返回元素是否仍在DOM中"""
warn("is_alive属性即将弃用请用states.is_alive属性代替。", DeprecationWarning)
return self.states.is_alive
@property
def is_in_viewport(self):
"""返回元素是否出现在视口中,以元素可以接受点击的点为判断"""
warn("is_in_viewport属性即将弃用请用states.is_in_viewport属性代替。", DeprecationWarning)
return self.states.is_in_viewport
@property
def pseudo_before(self):
"""返回当前元素的::before伪元素内容"""
warn("pseudo_before属性即将弃用请用pseudo.before属性代替。", DeprecationWarning)
return self.pseudo.before
@property
def pseudo_after(self):
"""返回当前元素的::after伪元素内容"""
warn("pseudo_after属性即将弃用请用pseudo.after属性代替。", DeprecationWarning)
return self.pseudo.after
@property
def obj_id(self):
"""返回js中的object id"""
warn("obj_id属性即将弃用请用ids.obj_id属性代替。", DeprecationWarning)
return self._obj_id
@property
def node_id(self):
"""返回cdp中的node id"""
warn("node_id属性即将弃用请用ids.node_id属性代替。", DeprecationWarning)
return self._node_id
@property
def backend_id(self):
"""返回backend id"""
warn("backend_id属性即将弃用请用ids.backend_id属性代替。", DeprecationWarning)
return self._backend_id
@property
def doc_id(self):
"""返回所在document的object id"""
warn("doc_id属性即将弃用请用ids.doc_id属性代替。", DeprecationWarning)
return self._doc_id
class ChromiumShadowRoot(BaseElement):
"""ChromiumShadowRoot是用于处理ShadowRoot的类使用方法和ChromiumElement基本一致"""
@ -1156,37 +1014,6 @@ class ChromiumShadowRoot(BaseElement):
self._tag = r['localName'].lower()
return r['backendNodeId']
# ------------准备废弃--------------
@property
def obj_id(self):
"""返回js中的object id"""
warn("obj_id属性即将弃用请用ids.obj_id属性代替。", DeprecationWarning)
return self._obj_id
@property
def node_id(self):
"""返回cdp中的node id"""
warn("node_id属性即将弃用请用ids.node_id属性代替。", DeprecationWarning)
return self._node_id
@property
def backend_id(self):
"""返回backend id"""
warn("backend_id属性即将弃用请用ids.backend_id属性代替。", DeprecationWarning)
return self._backend_id
@property
def is_enabled(self):
"""返回元素是否可用"""
warn("is_enabled属性即将弃用请用states.is_enabled属性代替。", DeprecationWarning)
return self.states.is_enabled
@property
def is_alive(self):
"""返回元素是否仍在DOM中"""
warn("is_alive属性即将弃用请用states.is_alive属性代替。", DeprecationWarning)
return self.states.is_alive
class Ids(object):
def __init__(self, ele):
@ -2095,7 +1922,7 @@ class ChromiumSelect(object):
mode = 'false' if cancel else 'true'
timeout = timeout if timeout is not None else self._ele.page.timeout
condition = {condition} if isinstance(condition, str) else set(condition)
condition = {condition} if isinstance(condition, (str, int)) else set(condition)
if para_type in ('text', 'value'):
return self._text_value(condition, para_type, mode, timeout)

View File

@ -6,7 +6,6 @@
from re import search
from threading import Thread
from time import sleep, perf_counter
from warnings import warn
from .chromium_base import ChromiumBase, ChromiumPageScroll, ChromiumBaseSetter, ChromiumBaseWaiter
from .chromium_element import ChromiumElement, ChromiumElementWaiter
@ -604,46 +603,6 @@ class ChromiumFrame(ChromiumBase):
sleep(1)
self.driver.stop()
# -------------准备废弃------------
def set_attr(self, attr, value):
"""设置frame元素attribute属性
:param attr: 属性名
:param value: 属性值
:return: None
"""
warn("set_attr()方法即将弃用请用set.attr()方法代替。", DeprecationWarning)
self.set.attr(attr, value)
@property
def is_displayed(self):
"""返回frame元素是否显示"""
warn("is_displayed属性即将弃用请用states.is_displayed属性代替。", DeprecationWarning)
return self.states.is_displayed()
@property
def tab_id(self):
"""返回当前标签页id"""
warn("tab_id属性即将弃用请用ids.tab_id属性代替。", DeprecationWarning)
return self.ids.tab_id
@property
def backend_id(self):
"""返回cdp中的node id"""
warn("backend_id属性即将弃用请用ids.backend_id属性代替。", DeprecationWarning)
return self.ids.backend_id
@property
def obj_id(self):
"""返回frame元素的object id"""
warn("obj_id属性即将弃用请用ids.obj_id属性代替。", DeprecationWarning)
return self.ids.obj_id
@property
def node_id(self):
"""返回cdp中的node id"""
warn("node_id属性即将弃用请用ids.node_id属性代替。", DeprecationWarning)
return self.ids.node_id
class ChromiumFrameIds(object):
def __init__(self, frame):

View File

@ -377,44 +377,6 @@ class ChromiumPage(ChromiumBase):
self._alert.response_text = None
self._tab_obj.has_alert = True
# --------------准备弃用-------------
def set_main_tab(self, tab_id=None):
"""设置主tab
:param tab_id: 标签页id不传入则设置当前tab
:return: None
"""
warn("set_main_tab()方法即将弃用请用set.main_tab()方法代替。", DeprecationWarning)
self.set.main_tab(tab_id)
@property
def set_window(self):
"""返回用于设置窗口大小的对象"""
warn("set_window()方法即将弃用请用set.window.xxxx()方法代替。", DeprecationWarning)
return WindowSetter(self)
def wait_download_begin(self, timeout=None):
"""等待浏览器下载开始
:param timeout: 等待超时时间为None则使用页面对象timeout属性
:return: 是否等到下载开始
"""
warn("wait_download_begin()方法即将弃用请用wait.download_begin()方法代替。", DeprecationWarning)
return self.download_set.wait_download_begin(timeout)
def hide_browser(self):
"""隐藏浏览器窗口只在Windows系统可用"""
warn("hide_browser()方法即将弃用请用set.hide()方法代替。", DeprecationWarning)
show_or_hide_browser(self, hide=True)
def show_browser(self):
"""显示浏览器窗口只在Windows系统可用"""
warn("show_browser()方法即将弃用请用set.show()方法代替。", DeprecationWarning)
show_or_hide_browser(self, hide=False)
def to_front(self):
"""激活当前标签页使其处于最前面"""
warn("to_front()方法即将弃用请用set.tab_to_front()方法代替。", DeprecationWarning)
self.set.tab_to_front()
class ChromiumPageWaiter(ChromiumBaseWaiter):
def download_begin(self, timeout=None):

View File

@ -6,7 +6,6 @@
from re import search
from time import sleep
from urllib.parse import urlparse
from warnings import warn
from DownloadKit import DownloadKit
from requests import Session, Response
@ -329,27 +328,6 @@ class SessionPage(BasePage):
raise ConnectionError(f'状态码:{r.status_code}')
return r, f'状态码:{r.status_code}'
def set_cookies(self, cookies):
"""为Session对象设置cookies
:param cookies: cookies信息
:return: None
"""
warn("set_cookies()方法即将弃用请用set.cookies()方法代替。", DeprecationWarning)
self.set.cookies(cookies)
def set_headers(self, headers):
"""设置通用的headers设置的headers值回逐个覆盖原有的不会清理原来的
:param headers: dict形式的headers
:return: None
"""
warn("set_headers()方法即将弃用请用set.headers()方法代替。", DeprecationWarning)
self.set.headers(headers)
def set_user_agent(self, ua):
"""设置user agent"""
warn("set_user_agent()方法即将弃用请用set.user_agent()方法代替。", DeprecationWarning)
self.set.user_agent(ua)
class SessionPageSetter(object):
def __init__(self, page):

View File

@ -6,7 +6,6 @@
from re import search
from time import sleep
from urllib.parse import urlparse
from warnings import warn
from DownloadKit import DownloadKit
from requests import Session, Response
@ -318,28 +317,6 @@ class SessionPage(BasePage):
raise ConnectionError(f'状态码:{r.status_code}')
return r, f'状态码:{r.status_code}'
# --------------准备废弃----------------
def set_cookies(self, cookies):
"""为Session对象设置cookies
:param cookies: cookies信息
:return: None
"""
warn("set_cookies()方法即将弃用请用set.cookies()方法代替。", DeprecationWarning)
self.set.cookies(cookies)
def set_headers(self, headers):
"""设置通用的headers设置的headers值回逐个覆盖原有的不会清理原来的
:param headers: dict形式的headers
:return: None
"""
warn("set_headers()方法即将弃用请用set.headers()方法代替。", DeprecationWarning)
self.set.headers(headers)
def set_user_agent(self, ua):
"""设置user agent"""
warn("set_user_agent()方法即将弃用请用set.user_agent()方法代替。", DeprecationWarning)
self.set.user_agent(ua)
class SessionPageSetter(object):
def __init__(self, page):

View File

@ -460,31 +460,6 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
self._tab_obj = None
self._has_driver = None
# ---------------准备废弃---------------
def set_cookies(self, cookies, set_session=True, set_driver=True):
"""添加cookies信息到浏览器或session对象
:param cookies: 可以接收`CookieJar``list``tuple``str``dict`格式的`cookies`
:param set_session: 是否设置到Session对象
:param set_driver: 是否设置到浏览器
:return: None
"""
# 添加cookie到driver
warn("set_cookies()方法即将弃用请用set.user_agent()方法代替。", DeprecationWarning)
self.set.cookies(cookies, set_session, set_driver)
def set_headers(self, headers) -> None:
"""设置固定发送的headers
:param headers: dict格式的headers数据
:return: None
"""
warn("set_headers()方法即将弃用请用set.headers()方法代替。", DeprecationWarning)
self.set.headers(headers)
def set_user_agent(self, ua, platform=None):
"""设置user agentd模式下只有当前tab有效"""
warn("set_user_agent()方法即将弃用请用set.user_agent()方法代替。", DeprecationWarning)
self.set.user_agent(ua, platform)
class WebPageSetter(ChromiumPageSetter):
def __init__(self, page):