【无标题】DrissionPage模块(七)

7. _units目录

_units目录结构

7.1 actions.py

Actions.py定义的类和函数:

序号

名称

说明

1

Actions(object)

用于实现动作链的类

2

location_to_client(page, lx, ly)

对坐标转换为视口坐标

7.1.1 Actions类

Actions类

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: ChromiumBase对象

move_to(ele_or_loc, offset_x=0, offset_y=0, duration=.5)

鼠标移动到元素中点,或页面上的某个绝对坐标。可设置偏移量。

当带偏移量时,偏移量相对于元素左上角坐标。

ele_or_loc:元素对象/绝对坐标或文本定位符,坐标为tuple(int, int)形式

offset_x: 偏移量x

offset_y: 偏移量y

duration: 拖动用时,传入0即瞬间到达

return: self

move(offset_x=0, offset_y=0, duration=.5)

鼠标相对当前位置移动若干位置

        :param offset_x: 偏移量x

        :param offset_y: 偏移量y

        :param duration: 拖动用时,传入0即瞬间到达

        :return: self

click(on_ele=None)

击鼠标左键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

r_click(on_ele=None)

点击鼠标右键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

m_click(on_ele=None)

点击鼠标中键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

db_click(on_ele=None)

双击鼠标左键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

hold(on_ele=None)

按住鼠标左键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

release(on_ele=None)

释放鼠标左键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

r_hold(on_ele=None)

按住鼠标右键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

r_release(on_ele=None)

释放鼠标右键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

m_hold(on_ele=None)

按住鼠标中键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

m_release(on_ele=None)

释放鼠标中键,可先移动到元素上

        :param on_ele: ChromiumElement元素或文本定位符

        :return: self

_hold(on_ele=None, button='left', count=1)

按下鼠标按键

        :param on_ele: ChromiumElement元素或文本定位符

        :param button: 要按下的按键,’left’, ‘right’, ‘middle’

        :param count: 点击次数

        :return: self

_release( button)

释放鼠标按键

        :param button: 要释放的按键

        :return: self

scroll(delta_y=0, delta_x=0, on_ele=None)

滚动鼠标滚轮,可先移动到元素上

        :param delta_y: 滚轮变化值y

        :param delta_x: 滚轮变化值x

        :param on_ele: ChromiumElement元素

        :return: self

up(pixel)

标向上移动若干像素

        :param pixel: 鼠标移动的像素值

        :return: self

down(pixel)

鼠标向下移动若干像素

        :param pixel: 鼠标移动的像素值

        :return: self

left(pixel)

鼠标向左移动若干像素

        :param pixel: 鼠标移动的像素值

        :return: self

right(self, pixel)

鼠标向右移动若干像素

        :param pixel: 鼠标移动的像素值

        :return: self

key_down(key)

按下键盘上的按键,

        :param key: 使用Keys获取的按键,或'DEL'形式按键名称

        :return: self

key_up(key)

提起键盘上的按键

        :param key: 按键,特殊字符见Keys

        :return: self

type(self, keys)

用模拟键盘按键方式输入文本,可输入字符串,也可输入组合键

        :param keys: 要按下的按键,特殊字符和多个文本可用list或tuple传入

        :return: self

input(ext)

输入文本,也可输入组合键,组合键用tuple形式输入

        :param text: 文本值或按键组合

        :return: self

wait(second, scope=None)

等待若干秒,如传入两个参数,等待时间为这两个数间的一个随机数

        :param second: 秒数

        :param scope: 随机数范围

        :return: None

_get_key_data(key, action)

获取用于发送的按键信息

        :param key: 按键

        :param action: 'keyDown' 或 'keyUp'

        :return: 按键信息

7.1.2 函数

函数

功能

说明

location_to_client(page, lx, ly)

绝对坐标转换为视口坐标(x, y)

​​​​​​​7.2 clicker.py

clicker.py定义的类和函数

序号

名称

说明

7.2..1

Clicker(object)

用于实现动作链的类

7.2.1 Clicker类

Clicker(object)

属性和方法

功能

本类定义的方法

__init__(self, ele)

ele: ChromiumElement

__call__(self, by_js=False, timeout=1.5, wait_stop=True)

点击元素

如果遇到遮挡,可选择是否用js点击

by_js: 是否用js点击,为None时先用模拟点击,遇到遮挡改用js,为True时直接用js点击,为False时只用模拟点击

timeout: 模拟点击的超时时间(秒),等待元素可见、可用、进入视口

wait_stop: 是否等待元素运动结束再执行点击

return: 是否点击成功

left(by_js=False, timeout=1.5, wait_stop=True)

点击元素,可选择是否用js点击

by_js: 是否用js点击,为None时先用模拟点击,遇到遮挡改用js,为True时直接用js点击,为False时只用模拟点击

timeout: 模拟点击的超时时间(秒),等待元素可见、可用、进入视口

wait_stop: 是否等待元素运动结束再执行点击

return: 是否点击成功

right()

右键单击

middle(get_tab=True)

中键单击,默认返回新出现的tab对象

get_tab: 是否返回新tab对象,为False则返回None

return: Tab对象或None

at(offset_x=None, offset_y=None, button='left', count=1)

带偏移量点击本元素,相对于左上角坐标。不传入x或y值时点击元素中间点

offset_x: 相对元素左上角坐标的x轴偏移量

offset_y: 相对元素左上角坐标的y轴偏移量

button: 点击哪个键,可选 left, middle, right, back, forward

count: 点击次数

return: None

multi(times=2)

多次点击

times: 默认双击

return: None

to_download(save_path=None, rename=None, suffix=None, new_tab=False, by_js=False, timeout=None)

点击触发下载

 save_path: 保存路径,为None保存在原来设置的,如未设置保存到当前路径

rename: 重命名文件名

suffix: 指定文件后缀

new_tab: 该下载是否在新tab中触发

by_js: 是否用js方式点击,逻辑与click()一致

timeout: 等待下载触发的超时时间,为None则使用页面对象设置

return: DownloadMission对象

to_upload(file_paths, by_js=False)

触发上传文件选择框并自动填入指定路径

file_paths: 文件路径,如果上传框支持多文件,可传入列表或字符串,字符串时多个文件用回车分隔

by_js: 是否用js方式点击,逻辑与click()一致

return: None

for_new_tab(by_js=False)

点击后等待新tab出现并返回其对象

by_js: 是否使用js点击,逻辑与click()一致

return: 新标签页对象,如果没有等到新标签页出现则抛出异常

_click(client_x, client_y, button='left', count=1)

实施点击

client_x: 视口中的x坐标

client_y: 视口中的y坐标

button: 'left' 'right' 'middle'  'back' 'forward'

count: 点击次数

return: None

twice()

双击元素

multiple(times=2)

多次点击

times: 默认双击

return: None

​​​​​​​7.3 cookies_setter.py

cookies_setter.py定义的类和函数:

序号

名称

说明

1

CookiesSetter(object)

2

SessionCookiesSetter(object)

3

WebPageCookiesSetter(CookiesSetter, SessionCookiesSetter)

7.3.1 CookiesSetter类

CookiesSetter(object)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: ChromiumBase对象

__call__(self, cookies)

置一个或多个cookie

        :param cookies: cookies信息

        :return: None

remove(name, url=None, domain=None, path=None)

删除一个cookie

        :param name: cookie的name字段

        :param url: cookie的url字段,可选

        :param domain: cookie的domain字段,可选

        :param path: cookie的path字段,可选

        :return: None

clear()

清除cookies

7.3.2 SessionCookiesSetter类

SessionCookiesSetter(object)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: ChromiumBase对象

__call__(self, cookies)

置一个或多个cookie

        :param cookies: cookies信息

        :return: None

remove(name)

删除一个cookie

        :param name: cookie的name字段

        :return: None

clear()

清除cookies

7.3.3 WebPageCookiesSetter类

WebPageCookiesSetter(CookiesSetter, SessionCookiesSetter)

属性和方法

功能

本类定义的方法

__call__(self, cookies)

设置多个cookie,注意不要传入单个

        :param cookies: cookies信息

        :return: None

remove(name, url=None, domain=None, path=None)

删除一个cookie

       :param name: cookie的name字段

        :param url: cookie的url字段,可选,d模式时才有效

        :param domain: cookie的domain字段,可选,d模式时才有效

        :param path: cookie的path字段,可选,d模式时才有效

        :return: None

clear()

清除cookies

​​​​​​​7.4 downloader.py

downloader.py定义的类和函数:

序号

名称

说明

1

DownloadManager(object)

管理下载器的类

2

TabDownloadSettings(object)

管理下载设置的类

3

DownloadMission(object)

管理下载任务的类

​​​​​​​7.4.1 DownloadManager类

DownloadManager(object)

属性和方法

功能

本类定义的方法

__init__(self, browser)

browser: Browser对象

@property

def missions(self)

返回所有未完成的下载任务

set_path(self, tab, path)

设置某个tab的下载路径,tab: 页面对象,path: 下载路径(绝对路径str)

        :return: None

set_rename(self, tab_id, rename=None, suffix=None)

设置某个tab的重命名文件名

        :param tab_id:标签页id

        :param rename:文件名,可不含后缀,会自动使用远程文件后缀

        :param suffix:后缀名,显式设置后缀名,不使用远程文件后缀

        :return: None

set_file_exists(self, tab_id, mode)

设置某个tab下载文件重名时执行的策略

        :param tab_id: tab id

        :param mode: 下载路径

        :return: None

set_flag(self, tab_id, flag)

设置某个tab的重命名文件名

        :param tab_id: tab id

        :param flag: 等待标志

        :return: None

get_flag(self, tab_id)

获取tab下载等待标记,tab_id:标签页id,return:任务对象或False

get_tab_missions(self, tab_id)

获取某个tab正在下载的任务,tab_id:标签页id,return:下载任务组成的列表

set_done(self, mission, state, final_path=None)

设置任务结束

mission: 任务对象

state: 任务状态

final_path: 最终路径

return: None

cancel(self, mission)

取消任务,mission: 任务对象,return: None

skip(self, mission)

跳过任务

        :param mission: 任务对象

        :return: None

clear_tab_info(self, tab_id)

tab关闭时清除有关信息

ab_id:标签页id

return: None

_onDownloadWillBegin(self, **kwargs)

用于获取弹出新标签页触发的下载任务

_onDownloadProgress(self, **kwargs)

下载状态变化时执行

​​​​​​​7.4.2 TabDownloadSettings类

TabDownloadSettings(object)

属性和方法

功能

本类定义的方法

__new__(cls, tab_id)

tab_id: tab id

__init__(self, tab_id)

tab_id: tab id

​​​​​​​7.4.3 DownloadMission类

DownloadMission(object)

属性和方法

功能

本类定义的方法

__init__(self, mgr, tab_id, _id, path, name, url, save_path)

        :param mgr: BrowserDownloadManager对象

        :param tab_id: 标签页id

        :param _id: 任务id

        :param path: 保存路径

        :param name: 文件名

        :param url: url

        :param save_path: 下载路径

__repr__(self)

@property

def rate()

以百分比形式返回下载进度

@property

def is_done()

返回任务是否在运行中

cancel()

取消该任务,如任务已完成,删除已下载的文件

wait(show=True, timeout=None, cancel_if_timeout=True)

​​​​​​​7.5 listener.py

listener.py定义的类和函数:

序号

名称

说明

1

Listener(object)

监听器基类

2

FrameListener(Listener)

3

DataPacket(object)

返回的数据包管理类

4

Request(object)

5

Response(object)

6

ExtraInfo(object)

7

RequestExtraInfo(ExtraInfo)

8

ResponseExtraInfo(ExtraInfo)

9

FailInfo(object)

​​​​​​​7.5.1 Listener类

Listener(object)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: ChromiumBase对象

@property

def targets(self)

返回监听目标

set_targets(targets=True,

is_regex=False,

method=('GET', 'POST'),

 res_type=True)

指定要等待的数据包

targets: 要匹配的数据包url特征,可用list等传入多个,为True时获取所有

is_regex: 设置的target是否正则表达式

method: 设置监听的请求类型,可指定多个,为True时监听全部

res_type: 设置监听的资源类型,可指定多个,为True时监听全部,可指定的值有:

Document, Stylesheet, Image, Media, Font, Script, TextTrack, XHR, Fetch, Prefetch, EventSource, WebSocket, Manifest, SignedExchange, Ping, CSPViolationReport, Preflight, Other

return: None

start(targets=None,

is_regex=None,

method=None,

res_type=None)

拦截目标请求,每次拦截前清空结果

targets: 要匹配的数据包url特征,可用list等传入多个,为True时获取所有

is_regex: 设置的target是否正则表达式,为None时保持原来设置

method: 设置监听的请求类型,可指定多个,默认('GET', 'POST'),为True时监听全部,为None时保持原来设置

res_type: 设置监听的资源类型,可指定多个,默认为True时监听全部,为None时保持原来设置,可指定的值有:Document, Stylesheet, Image, Media, Font, Script, TextTrack, XHR, Fetch, Prefetch, EventSource, WebSocket, Manifest, SignedExchange, Ping, CSPViolationReport, Preflight, Other

return: None

wait(count=1,

timeout=None,

fit_count=True,

raise_err=None)

等待符合要求的数据包到达指定数量

count: 需要捕捉的数据包数量

timeout: 超时时间,为None无限等待

fit_count: 是否必须满足总数要求,发生超时,为True返回False,为False返回已捕捉到的数据包

raise_err: 超时时是否抛出错误,为None时根据Settings设置

return: count为1时返回数据包对象,大于1时返回列表,超时且fit_count为True时返回False

steps(count=None, timeout=None, gap=1)

用于单步操作,可实现每收到若干个数据包执行一步操作(如翻页)

        :param count: 需捕获的数据包总数,为None表示无限

        :param timeout: 每个数据包等待时间,为None表示无限

        :param gap: 每接收到多少个数据包返回一次数据

        :return: 用于在接收到监听目标时触发动作的可迭代对象

stop()

停止监听,清空已监听到的列表

pause(clear=True)

暂停监听

        :param clear: 是否清空已获取队列

        :return: None

resume()

继续暂停的监听

clear()

清空结果

wait_silent(timeout=None,

targets_only=False,

limit=0)

等待所有请求结束

        :param timeout: 超时,为None时无限等待

        :param targets_only: 是否只等待targets指定的请求结束

        :param limit: 剩下多少个连接时视为结束

        :return: 返回是否等待成功

_to_target(target_id, address, owner)

切换监听的页面对象

        :param target_id: 新页面对象_target_id

        :param address: 新页面对象address

        :param owner: 新页面对象

        :return: None

_set_callback()

设置监听请求的回调函数

_requestWillBeSent(**kwargs)

接收到请求时的回调函数

_requestWillBeSentExtraInfo(**kwargs)

接收到请求额外信息时的回调函数

_response_received(**kwargs)

接收到返回信息时处理方法

_responseReceivedExtraInfo(**kwargs)

接收到返回额外信息时的回调函数

_loading_finished(**kwargs)

请求完成时处理方法

_loading_failed(**kwargs)

请求失败时的回调方法

​​​​​​​7.5.2 FrameListener(Listener)

FrameListener(Listener)

属性和方法

功能

本类定义的方法

_requestWillBeSent(self, **kwargs)

接收到请求时的回调函数

_response_received(self, **kwargs)

接收到返回信息时处理方法

​​​​​​​7.5.3 DataPacket(object)

DataPacket(object)

属性和方法

功能

本类定义的方法

__init__(self, tab_id, target)

        :param tab_id: 产生这个数据包的tab的id

        :param target: 监听目标

@property

def _request_extra_info()

返回

@property

def _response_extra_info()

返回

@property

def url()

返回请求的url

@property

def method()

返回请求方式

@property

def frameId()

@property

def resourceType()

@property

def request()

返回请求信息

@property

def response()

返回响应信息

@property

def fail_info()

wait_extra_info(stimeout=None)

等待额外的信息加载完成

        :param timeout: 超时时间,None为无限等待

        :return: 是否等待成功

​​​​​​​7.5.4 Request(object)

Request(object)

属性和方法

功能

本类定义的方法

__init__(data_packet, raw_request, post_data)

@property

def headers()

以大小写不敏感字典返回headers数据

@property

def postData()

返回postData数据

@property

def cookies()

以list形式返回发送的cookies

@property

def extra_info()

返回额外数据

​​​​​​​7.5.5 Response(object)

Response(object)

属性和方法

功能

本类定义的方法

__init__(self, data_packet, raw_response, raw_body, base64_body)

@property

def headers(self)

以大小写不敏感字典返回headers数据

@property

def raw_body(self)

返回未被处理的body文本

@property

def body(self)

返回body内容,如果是json格式,自动进行转换,如果时图片格式,进行base64转换,其它格式直接返回文本

@property

def extra_info(self)

​​​​​​​7.5.6 ExtraInfo(object)

ExtraInfo(object)

属性和方法

功能

本类定义的方法

__init__(self, extra_info)

@property

def all_info()

以dict形式返回所有额外信息

​​​​​​​7.5.7 RequestExtraInfo(ExtraInfo)

RequestExtraInfo(ExtraInfo)

属性和方法

功能

本类定义的方法

暂无

​​​​​​​7.5.8 ResponseExtraInfo(ExtraInfo)

ResponseExtraInfo(ExtraInfo)

属性和方法

功能

本类定义的方法

暂无

​​​​​​​7.5.9 FailInfo(object)

FailInfo(object)

属性和方法

功能

本类定义的方法

__init__(self, data_packet, fail_info)

​​​​​​​7.6 rect.py

定义的类和函数:

序号

名称

说明

1

ElementRect(object)

2

TabRect(object)

3

FrameRect(object)

异域iframe使用

​​​​​​​7.6.1 ElementRect(object)

属性和方法

功能

本类定义的方法

__init__(self, ele)

ele: ChromiumElement

@property

def corners(self)

返回元素四个角坐标,顺序:左上、右上、右下、左下,没有大小的元素抛出NoRectError

@property

def viewport_corners(self)

返回元素四个角视口坐标,顺序:左上、右上、右下、左下,没有大小的元素抛出NoRectError

@property

def size(self)

返回元素大小,格式(宽, 高)

@property

    def location(self)

返回元素左上角的绝对坐标

@property

def midpoint(self)

返回元素中间点的绝对坐标

@property

def click_point(self)

返回元素接受点击的点的绝对坐标

@property

def viewport_location(self)

返回元素左上角在视口中的坐标

@property

    def viewport_midpoint(self)

返回元素中间点在视口中的坐标

@property

def viewport_click_point(self)

返回元素接受点击的点视口坐标

@property

def screen_location(self)

返回元素中点在屏幕上坐标,左上角为(0, 0)

@property

def screen_midpoint(self)

返回元素中点在屏幕上坐标,左上角为(0, 0)

@property

def screen_click_point(self)

按照类型返回在可视窗口中的范围

quad: 方框类型,margin border padding

return: 四个角坐标

_get_viewport_rect(self, quad)

_get_page_coord(self, x, y)

根据视口坐标获取绝对坐标

​​​​​​​7.6.2 TabRect(object)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: Page对象和Tab对象

@property

    def window_state(self)

返回窗口状态:normal、fullscreen、maximized、minimized

@property

    def window_location(self)

返回窗口在屏幕上的坐标,左上角为(0, 0)

@property

    def window_size(self)

返回窗口大小

@property

    def page_location(self)

返回页面左上角在屏幕中坐标,左上角为(0, 0)

@property

    def viewport_location(self)

返回视口在屏幕中坐标,左上角为(0, 0)

@property

    def size(self)

返回页面总宽高,格式:(宽, 高)

@property

    def viewport_size(self)

返回视口宽高,不包括滚动条,格式:(宽, 高)

@property

    def viewport_size_with_scrollbar(self)

返回视口宽高,包括滚动条,格式:(宽, 高)

_get_page_rect(self)

获取页面范围信息

_get_window_rect(self)

获取窗口范围信息

​​​​​​​7.6.3 FrameRect(object)

属性和方法

功能

本类定义的方法

__init__(self, frame)

frame: ChromiumFrame对象

@property

    def location(self)

返回iframe元素左上角的绝对坐标

@property

    def viewport_location(self)

返回元素在视口中坐标,左上角为(0, 0)

@property

    def screen_location(self)

返回元素左上角在屏幕上坐标,左上角为(0, 0)

@property

    def size(self)

返回frame内页面尺寸,格式:(宽, 高)

@property

    def viewport_size(self)

返回视口宽高,格式:(宽, 高)

@property

    def corners(self)

返回元素四个角坐标,顺序:左上、右上、右下、左下

@property

    def viewport_corners(self)

返回元素四个角视口坐标,顺序:左上、右上、右下、左下

​​​​​​​7.7 screencast.py

定义的类和函数:

序号

名称

说明

1

Screencast(object)

2

ScreencastMode(object)

​​​​​​​7.7.1 Screencast(object)

属性和方法

功能

本类定义的方法

__init__(self, owner)

@property

    def set_mode(self)

返回用于设置录屏模式的对象

start(self, save_path=None)

开始录屏

        :param save_path: 录屏保存位置

        :return: None

stop(self, video_name=None)

停止录屏

        :param video_name: 视频文件名,为None时以当前时间名命

        :return: 文件路径

set_save_path(self, save_path=None)

设置保存路径

        :param save_path: 保存路径

        :return: None

_run(self)

非节俭模式运行方法

_onScreencastFrame(self, **kwargs)

节俭模式运行方法

​​​​​​​7.7.2 ScreencastMode(object)

属性和方法

功能

本类定义的方法

__init__(self, screencast)

video_mode(self)

持续视频模式,生成的视频没有声音

frugal_video_mode(self)

设置节俭视频模式,页面有变化时才录制,生成的视频没有声音

js_video_mode(self)

设置使用js录制视频模式,可生成有声音的视频,但需要手动启动

frugal_imgs_mode(self)

设置节俭视频模式,页面有变化时才截图

imgs_mode(self)

设置图片模式,持续对页面进行截图

​​​​​​​7.8 scroller.py

定义的类和函数:

序号

名称

说明

1

Scroller(object)

用于滚动的对象

2

ElementScroller(Scroller)

3

PageScroller(Scroller)

4

FrameScroller(PageScroller)

​​​​​​​7.8.1 scroller(object)

属性和方法

功能

说明

本类定义的方法

__init__(self, ele)

ele: 元素对象

_run_js(self, js)

self.t1='window'

 self.t2='document.documentElement'

由PageScroller(Scroller)传入

js = js.format(self.t1, self.t2, self.t2)

_driver.run_js(js)

_wait_scrolled()

to_top(self)

滚动到顶端,水平位置不变

_run_js('{}.scrollTo({}.scrollLeft, 0);')

to_bottom(self):

滚动到底端,水平位置不变

_run_js('{}.scrollTo({}.scrollLeft, {}.scrollHeight/2);')

to_rightmost(self)

滚动到最右边,垂直位置不变

_run_js('{}.scrollTo({}.scrollWidth, {}.scrollTop);')

to_leftmost(self)

滚动到最左边,垂直位置不变

_run_js('{}.scrollTo(0, {}.scrollTop);')

to_location(self, x, y)

滚动到指定位置,x: 水平距离,y: 垂直距离

return: None

_run_js(f'{{}}.scrollTo({x}, {y});')

up(self, pixel=300)

向上滚动若干像素,水平位置不变,pixel: 滚动的像素

return: None

down(self, pixel=300)

向下滚动若干像素,水平位置不变,pixel: 滚动的像素

return: None

left(self, pixel=300)

向左滚动若干像素,垂直位置不变,pixel: 滚动的像素

return: None

right(self, pixel=300)

向右滚动若干像素,垂直位置不变,pixel: 滚动的像素

return: None

_wait_scrolled(self)

等待滚动结束

​​​​​​​7.8.2 ElementScroller(Scroller)

属性和方法

功能

本类定义的方法

to_see(self, center=None)

滚动页面直到元素可见

        :param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中

        :return: None

to_center(self)

元素尽量滚动到视口中间

​​​​​​​7.8.3 PageScroller(Scroller)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: 页面对象

to_see(self, loc_or_ele, center=None)

滚动页面直到元素可见

        :param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串

        :param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中

        :return: None

_to_see(self, ele, center)

执行滚动页面直到元素可见

        :param ele: 元素对象

        :param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中

        :return: None

​​​​​​​7.8.4 FrameScroller(PageScroller)

属性和方法

功能

本类定义的方法

__init__(self, frame)

frame: ChromiumFrame对象

to_see(self, loc_or_ele, center=None)

动页面直到元素可见

        :param loc_or_ele: 元素的定位信息,可以是loc元组,或查询字符串

        :param center: 是否尽量滚动到页面正中,为None时如果被遮挡,则滚动到页面正中

        :return: None

​​​​​​​7.9 selector.py

定义的类和函数:

序号

名称

说明

1

SelectElement(object)

用于处理select 标签的类

7.9.1 SelectElement(object)

属性和方法

功能

本类定义的方法

__init__(self, ele)

ele: select元素对象

__call__(self, text_or_index, timeout=None)

选定下拉列表中子元素

text_or_index: 根据文本、值选或序号择选项,若允许多选,传入list或tuple可多选

timeout: 超时时间,不输入默认实用页面超时时间

return: None

@property

def is_multi(self)

返回是否多选表单

@property

def options(self)

返回第一个被选中的option元素

@property

def selected_options(self)

返回所有被选中的option元素列表

return: ChromiumElement对象组成的列表

all(self)

全选

invert(self)

反选

clear(self)

清除所有已选项

by_text(self, text, timeout=None)

此方法用于根据text值选择项。当元素是多选列表时,可以接收list或tuple

text: text属性值,传入list或tuple可选择多项

timeout: 超时时间,为None默认使用页面超时时间

return: 是否选择成功

by_value(self, value, timeout=None)

此方法用于根据value值选择项。当元素是多选列表时,可以接收list或tuple

value: value属性值,传入list或tuple可选择多项

timeout: 超时时间,为None默认使用页面超时时间

return: 是否选择成功

by_index(self, index, timeout=None)

此方法用于根据index值选择项。当元素是多选列表时,可以接收list或tuple

index: 序号,从1开始,可传入负数获取倒数第几个,传入list或tuple可选择多项

timeout: 超时时间,为None默认使用页面超时时间

return: 是否选择成功

by_locator(self, locator, timeout=None)

用定位符选择指定的项

locator: 定位符

timeout: 超时时间

return: 是否选择成功

by_option(self, option)

选中单个或多个option元素

option: option元素或它们组成的列表

return: None

cancel_by_text(self, text, timeout=None)

此方法用于根据text值取消选择项。当元素是多选列表时,可以接收list或tuple

text: 文本,传入list或tuple可取消多项

timeout: 超时时间,不输入默认实用页面超时时间

return: 是否取消成功

cancel_by_value(self, value, timeout=None)

此方法用于根据value值取消选择项。当元素是多选列表时,可以接收list或tuple

value: value属性值,传入list或tuple可取消多项

timeout: 超时时间,不输入默认实用页面超时时间

return: 是否取消成功

cancel_by_index(self, index, timeout=None)

此方法用于根据index值取消选择项。当元素是多选列表时,可以接收list或tuple

index: 序号,从1开始,可传入负数获取倒数第几个,传入list或tuple可取消多项

timeout: 超时时间,不输入默认实用页面超时时间

return: 是否取消成功

cancel_by_locator(self, locator, timeout=None)

用定位符取消选择指定的项

locator: 定位符

timeout: 超时时间

return: 是否选择成功

cancel_by_option(self, option)

取消选中单个或多个option元素

option: option元素或它们组成的列表

return: None

_by_loc(self, loc, timeout=None, cancel=False)

用定位符取消选择指定的项

loc: 定位符

timeout: 超时时间

cancel: 是否取消选择

return: 是否选择成功

_select(self, condition, para_type='text', cancel=False, timeout=None)

选定或取消选定下拉列表中子元素

condition: 根据文本、值选或序号择选项,若允许多选,传入list或tuple可多选

para_type: 参数类型,可选 'text'、'value'、'index'

cancel: 是否取消选择

return: 是否选择成功

_text_value(self, condition, para_type, mode, timeout)

执行text和value搜索

condition: 条件set

para_type: 参数类型,可选 'text'、'value'

mode: 'true' 或 'false'

timeout: 超时时间

return: 是否选择成功

_index(self, condition, mode, timeout)

执行index搜索

        :param condition: 条件set

        :param mode: 'true' 或 'false'

        :param timeout: 超时时间

        :return: 是否选择成功

_select_options(self, option, mode)

选中或取消某个选项

        :param option: options元素对象

        :param mode: 选中还是取消

        :return: None

_dispatch_change(self)

触发修改动作

​​​​​​​7.10 setter.py

定义的类和函数:

序号

名称

说明

1

BasePageSetter(object)

管理页面设置的基类

2

ChromiumBaseSetter(BasePageSetter)

管理d模式页面设置的类

3

TabSetter(ChromiumBaseSetter)

管理d模式标签页设置的类

4

ChromiumPageSetter(TabSetter)

管理d模式页面驱动设置的类

5

SessionPageSetter(BasePageSetter)

管理s模式页面设置的类

6

WebPageSetter(ChromiumPageSetter)

管理s模和d模式兼容时页面设置的类

7

WebPageTabSetter(TabSetter)

管理s模和d模式兼容时标签页设置的类

8

ChromiumElementSetter(object)

管理d模式元素设置的类

9

ChromiumFrameSetter(ChromiumBaseSetter)

管理d模式表单设置的类

10

LoadMode(object)

管理页面加载模式的类

11

PageScrollSetter(object)

管理页面滚动条设置的类

12

WindowSetter(object)

用于设置窗口大小的类

​​​​​​​7.10.1 BasePageSetter(object)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: BasePage对象

NoneElement_value(value=None, on_off=True)

设置空元素是否返回设定值

        :param value: 返回的设定值

        :param on_off: 是否启用

        :return: None

​​​​​​​7.10.2 ChromiumBaseSetter(BasePageSetter)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: BasePage对象

@property

def load_mode(self)

返回用于设置页面加载策略的对象

return LoadMode(self._owner)

@property

    def scroll(self)

返回用于设置页面滚动设置的对象

return PageScrollSetter(self._owner.scroll)

@property

    def cookies(self)

返回用于设置cookies的对象

retry_times(self, times)

设置连接失败重连次数

retry_interval(self, interval)

设置连接失败重连间隔

timeouts(self, base=None, page_load=None, script=None, implicit=None)

设置超时时间,单位为秒

        :param base: 基本等待时间,除页面加载和脚本超时,其它等待默认使用

        :param page_load: 页面加载超时时间

        :param script: 脚本运行超时时间

        :return: None

user_agent(self, ua, platform=None)

为当前tab设置user agent,只在当前tab有效

        :param ua: user agent字符串

        :param platform: platform字符串

        :return: None

session_storage(self, item, value)

设置或删除某项sessionStorage信息

        :param item: 要设置的项

        :param value: 项的值,设置为False时,删除该项

        :return: None

local_storage(self, item, value)

设置或删除某项localStorage信息

        :param item: 要设置的项

        :param value: 项的值,设置为False时,删除该项

        :return: None

upload_files(self, files)

等待上传的文件路径

        :param files: 文件路径列表或字符串,字符串时多个文件用回车分隔

        :return: None

headers(self, headers)

设置固定发送的headers

        :param headers: dict格式的headers数据

        :return: None

auto_handle_alert(self, on_off=True, accept=True)

设置是否启用自动处理弹窗

        :param on_off: bool表示开或关

        :param accept: bool表示确定还是取消

        :return: None

blocked_urls(self, urls)

设置要忽略的url

urls: 要忽略的url,可用*通配符,可输入多个,传入None时清空已设置的内容

return: None

@property

def load_strategy(self)

返回用于设置页面加载策略的对象

​​​​​​​7/10.3 TabSetter(ChromiumBaseSetter)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: 标签页对象

@property

    def window(self)

返回用于设置浏览器窗口的对象

download_path(self, path)

设置下载路径,path: 下载路径,return: None

download_file_name(self, name=None, suffix=None)

设置下一个被下载文件的名称

name: 文件名,可不含后缀,会自动使用远程文件后缀

suffix: 后缀名,显式设置后缀名,不使用远程文件后缀

return: None

when_download_file_exists(self, mode)

设置当存在同名文件时的处理方式

mode: 可在 'rename', 'overwrite', 'skip', 'r', 'o', 's'中选择

return: None

activate(self)

使标签页处于最前面

​​​​​​​7.10.4 ChromiumPageSetter(TabSetter)

属性和方法

功能

本类定义的方法

tab_to_front(self, tab_or_id=None)

激活标签页使其处于最前面

        :param tab_or_id: 标签页对象或id,为None表示当前标签页

        :return: None

auto_handle_alert(self, on_off=True, accept=True, all_tabs=False)

设置是否启用自动处理弹窗

on_off: bool表示开或关

accept: bool表示确定还是取消

all_tabs: 是否为全局设置

return: None

​​​​​​​7.10.5 SessionPageSetter(BasePageSetter)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: SessionPage对象

@property

def cookies(self)

返回用于设置cookies的对象

retry_times(self, times)

设置连接失败时重连次数

retry_interval(self, interval)

设置连接失败时重连间隔

download_path(self, path)

设置下载路径,path: 下载路径,return: None

timeout(self, second)

设置连接超时时间,second: 秒数,return: None

encoding(self, encoding, set_all=True)

设置编码

encoding: 编码名称,如果要取消之前的设置,传入None

set_all: 是否设置对象参数,为False则只设置当前Response

return: None

headers(self, headers)

设置通用的headers,headers: dict形式的headers,return: None

header(self, name, value)

设置headers中一个项,name: 设置名称,value: 设置值,return: None

user_agent(self, ua)

设置user agent,ua: user agent,return: None

proxies(self, http=None, https=None)

设置proxies参数,http: http代理地址,https: https代理地址,return: None

auth(self, auth)

设置认证元组或对象,auth: 认证元组或对象,return: None

hooks(self, hooks)

设置回调方法,hooks: 回调方法,return: None

params(self, params)

设置查询参数字典,params: 查询参数字典,return: None

verify(self, on_off)

设置是否验证SSL证书,on_off: 是否验证SSL证书,return: None

cert(self, cert)

SSL客户端证书文件的路径(.pem格式),或(‘cert’, ‘key’)元组,cert: 证书路径或元组

stream(self, on_off)

设置是否使用流式响应内容,on_off: 是否使用流式响应内容,return: None

trust_env(self, on_off)

设置是否信任环境,on_off: 是否信任环境,return: None

max_redirects(self, times)

设置最大重定向次数,times: 最大重定向次数,return: None

add_adapter(self, url, adapter)

添加适配器,url: 适配器对应url,adapter: 适配器对象,return: None

​​​​​​​7.10.6 WebPageSetter(ChromiumPageSetter)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: 页面对象

@property

def cookies(self)

返回用于设置cookies的对象

headers(self, headers)

设置固定发送的headers,headers: dict格式的headers数据,return: None

user_agent(self, ua, platform=None)

设置user agent,d模式下只有当前tab有效

​​​​​​​7.10.7 WebPageTabSetter(TabSetter)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: 标签页对象

@property

def cookies(self)

返回用于设置cookies的对象

headers(self, headers)

设置固定发送的headers,headers: dict格式的headers数据,return: None

user_agent(self, ua, platform=None)

设置user agent,d模式下只有当前tab有效

​​​​​​​7.10.8 ChromiumElementSetter(object)

属性和方法

功能

本类定义的方法

__init__(self, ele)

ele: ChromiumElement

attr(self, name, value)

设置元素attribute属性,name: 属性名,value: 属性值,return: None

property(self, name, value)

设置元素property属性,name: 属性名,value: 属性值,return: None

innerHTML(self, html)

设置元素innerHTML,html: html文本,return: None

value(self, value)

设置元素value值,value: value值,return: None

​​​​​​​7.10.9 ChromiumFrameSetter(ChromiumBaseSetter)

属性和方法

功能

本类定义的方法

attr(self, name, value)

设置frame元素attribute属性,name: 属性名,value: 属性值,return: None

​​​​​​​7.10.10 LoadMode(object)

属性和方法

功能

本类定义的方法

__init__(self, owner)

owner: ChromiumBase对象

__call__(self, value)

设置加载策略,value: 可选 'normal', 'eager', 'none',return: None

normal(self)

设置页面加载策略为normal

eager(self)

设置页面加载策略为eager

none(self)

设置页面加载策略为none

​​​​​​​7.10.11 PageScrollSetter(object)

属性和方法

功能

__init__(self, scroll)

scroll: PageScroller对象

wait_complete(self, on_off=True)

设置滚动命令后是否等待完成,on_off: 开或关,return: None

smooth(self, on_off=True)

设置页面滚动是否平滑滚动,on_off: 开或关,return: None

​​​​​​​7.10.12 WindowSetter(object)

属性和方法

功能

__init__(self, owner)

owner: 页面对象

max(self)

窗口最大化

mini(self)

窗口最小化

full(self)

设置窗口为全屏

normal(self)

设置窗口为常规模式

size(self, width=None, height=None)

设置窗口大小,width: 窗口宽度,height: 窗口高度,return: None

location(self, x=None, y=None)

设置窗口在屏幕中的位置,相对左上角坐标,距离顶部距离,y: 距离左边距离,return: None

_get_info(self)

获取窗口位置及大小信息,自动调用

_perform(self, bounds)

执行改变窗口大小操作,bounds: 控制数据,return: None,自动调用

maximized(self)

窗口最大化

minimized(self)

窗口最小化

fullscreen(self)

设置窗口为全屏

hide(self)

隐藏浏览器窗口,只在Windows系统可用

show(self)

显示浏览器窗口,只在Windows系统可用

​​​​​​​7.11 states.py

定义的类和函数:

序号

名称

说明

1

ElementStates(object)

2

ShadowRootStates(object)

3

PageStates(object)

Page对象、Tab对象使用

4

FrameStates(object)

​​​​​​​7.11.1 ElementStates(object)

属性和方法

功能

__init__(self, ele)

ele: ChromiumElement

@property

    def is_selected(self)

返回元素是否被选择

@property

    def is_checked(self)

返回元素是否被选择

@property

    def is_displayed(self)

回元素是否显示

@property

    def is_enabled(self)

返回元素是否可用

@property

    def is_alive(self)

返回元素是否仍在DOM中

@property

    def is_in_viewport(self)

返回元素是否出现在视口中,以元素click_point为判断

@property

    def is_whole_in_viewport(self)

返回元素是否整个都在视口内

@property

    def is_covered(self)

返回元素是否被覆盖,与是否在视口中无关,如被覆盖返回覆盖元素的backend id,否则返回False

@property

    def has_rect(self)

返回元素是否拥有位置和大小,没有返回False,有返回四个角在页面中坐标组成的列表

​​​​​​​7.11.2 ShadowRootStates(object)

属性和方法

功能

__init__(self, ele)

ele: ChromiumElement

@property

    def is_enabled(self)

返回元素是否可用

@property

    def is_alive(self)

返回元素是否仍在DOM中

​​​​​​​7.11.3 PageStates(object)

属性和方法

功能

__init__(self, owner)

owner: ChromiumBase对象

@property

    def is_loading(self)

返回页面是否在加载状态

@property

    def is_alive(self)

返回页面对象是否仍然可用

@property

    def ready_state(self)

返回当前页面加载状态,'connecting' 'loading' 'interactive' 'complete'

 @property

    def has_alert(self)

返回当前页面是否存在弹窗

​​​​​​​7.11.4 FrameStates(object)

属性和方法

功能

__init__(self, frame)

frame: ChromiumFrame对象

@property

    def is_loading(self)

返回页面是否在加载状态

@property

    def is_alive(self)

返回frame元素是否可用,且里面仍挂载有frame

@property

    def ready_state(self)

返回加载状态

@property

    def is_displayed(self)

返回iframe是否显示

@property

    def has_alert(self)

返回当前页面是否存在弹窗

​​​​​​​7.12 waiter.py

定义的类和函数:

序号

名称

说明

1

OriginWaiter(object)

2

BaseWaiter(OriginWaiter)

3

TabWaiter(BaseWaiter)

4

PageWaiter(TabWaiter)

5

ElementWaiter(OriginWaiter)

等待元素在dom中某种状态,如删除、显示、隐藏

6

FrameWaiter(BaseWaiter, ElementWaiter)

​​​​​​​7.12.1 OriginWaiter(object)

属性和方法

功能

__call__(self, second, scope=None)

待若干秒,如传入两个参数,等待时间为这两个数间的一个随机数

        :param second: 秒数

        :param scope: 随机数范围

        :return: None

​​​​​​​7.12.2 BaseWaiter(OriginWaiter)

属性和方法

功能

__init__(self, page_or_ele)

page_or_ele: 页面对象或元素对象

ele_deleted(self, loc_or_ele, timeout=None, raise_err=None)

等待元素从DOM中删除

        :param loc_or_ele: 要等待的元素,可以是已有元素、定位符

        :param timeout: 超时时间,默认读取页面超时时间

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

ele_displayed(self, loc_or_ele, timeout=None, raise_err=None)

待元素变成显示状态

        :param loc_or_ele: 要等待的元素,可以是已有元素、定位符

        :param timeout: 超时时间,默认读取页面超时时间

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

ele_hidden(self, loc_or_ele, timeout=None, raise_err=None)

等待元素变成隐藏状态

        :param loc_or_ele: 要等待的元素,可以是已有元素、定位符

        :param timeout: 超时时间,默认读取页面超时时间

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

eles_loaded(self, locators, timeout=None, any_one=False, raise_err=None)

等待元素加载到DOM,可等待全部或任意一个

        :param locators: 要等待的元素,输入定位符,用list输入多个

        :param timeout: 超时时间,默认读取页面超时时间

        :param any_one: 是否等待到一个就返回

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 成功返回True,失败返回False

load_start(self, timeout=None, raise_err=None)

等待页面开始加载

        :param timeout: 超时时间,为None时使用页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

doc_loaded(self, timeout=None, raise_err=None)

等待页面加载完成

        :param timeout: 超时时间,为None时使用页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

upload_paths_inputted(self)

等待自动填写上传文件路径

download_begin(self, timeout=None, cancel_it=False)

等待浏览器下载开始,可将其拦截

        :param timeout: 超时时间,None使用页面对象超时时间

        :param cancel_it: 是否取消该任务

        :return: 成功返回任务对象,失败返回False

url_change(self, text, exclude=False, timeout=None, raise_err=None)

待url变成包含或不包含指定文本

text: 用于识别的文本

exclude: 是否排除,为True时当url不包含text指定文本时返回True

timeout: 超时时间

raise_err: 等待失败时是否报错,为None时根据Settings设置

return: 是否等待成功

title_change(self, text, exclude=False, timeout=None, raise_err=None)

待title变成包含或不包含指定文本

        :param text: 用于识别的文本

        :param exclude: 是否排除,为True时当title不包含text指定文本时返回True

        :param timeout: 超时时间

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

 _change(self, arg, text, exclude=False, timeout=None, raise_err=None)

等待指定属性变成包含或不包含指定文本

        :param arg: 要被匹配的属性

        :param text: 用于识别的文本

        :param exclude: 是否排除,为True时当属性不包含text指定文本时返回True

        :param timeout: 超时时间

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

_loading(self, timeout=None, start=True, gap=.01, raise_err=None)

等待页面开始加载或加载完成

        :param timeout: 超时时间,为None时使用页面timeout属性

        :param start: 等待开始还是结束

        :param gap: 间隔秒数

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

data_packets(self, count=1, timeout=None, fix_count: bool = True)

等待符合要求的数据包到达指定数量

        :param count: 需要捕捉的数据包数量

        :param timeout: 超时时间,为None无限等待

        :param fix_count: 是否必须满足总数要求,发生超时,为True返回False,为False返回已捕捉到的数据包

        :return: count为1时返回数据包对象,大于1时返回列表,超时且fix_count为True时返回False

load_complete(self, timeout=None, raise_err=None)

等待页面加载完成

        :param timeout: 超时时间,为None时使用页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

ele_loaded(self, locator, timeout=None, raise_err=None)

等待元素加载到DOM

        :param locator: 要等待的元素,输入定位符

        :param timeout: 超时时间,默认读取页面超时时间

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 成功返回元素对象,失败返回False

​​​​​​​7.12.3 TabWaiter(BaseWaiter)

属性和方法

功能

downloads_done(self, timeout=None, cancel_if_timeout=True)

等待所有浏览器下载任务结束

        :param timeout: 超时时间,为None时无限等待

        :param cancel_if_timeout: 超时时是否取消剩余任务

        :return: 是否等待成功

alert_closed(self)

等待弹出框关闭"

​​​​​​​7.12.4PageWaiter(TabWaiter)

属性和方法

功能

__init__(self, page)

new_tab(self, timeout=None, raise_err=None)

等待新标签页出现

        :param timeout: 等待超时时间,为None则使用页面对象timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 等到新标签页返回其id,否则返回False

all_downloads_done(self, timeout=None, cancel_if_timeout=True)

等待所有浏览器下载任务结束

        :param timeout: 超时时间,为None时无限等待

        :param cancel_if_timeout: 超时时是否取消剩余任务

        :return: 是否等待成功

​​​​​​​7.12.5 ElementWaiter(OriginWaiter)

属性和方法

功能

__init__(self, owner, ele)

待元素在dom中某种状态,如删除、显示、隐藏

        :param owner: 元素所在页面

        :param ele: 要等待的元素

deleted(self, timeout=None, raise_err=None)

等待元素从dom删除

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

displayed(self, timeout=None, raise_err=None)

等待元素从dom显示

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

hidden(self, timeout=None, raise_err=None)

等待元素从dom隐藏

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

covered(self, timeout=None, raise_err=None)

等待当前元素被遮盖

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

not_covered(self, timeout=None, raise_err=None)

等待当前元素不被遮盖

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

enabled(self, timeout=None, raise_err=None)

等待当前元素变成可用

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

disabled(self, timeout=None, raise_err=None)

等待当前元素变成不可用

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

disabled_or_deleted(self, timeout=None, raise_err=None)

等待当前元素变成不可用或从DOM移除

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

stop_moving(self, gap=.1, timeout=None, raise_err=None)

等待当前元素停止运动

        :param gap: 检测间隔时间

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

has_rect(self, timeout=None, raise_err=None)

等待当前元素有大小及位置属性

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :return: 是否等待成功

_wait_state(self, attr, mode=False, timeout=None, raise_err=None, err_text=None)

等待元素某个元素状态到达指定状态

        :param attr: 状态名称

        :param mode: True或False

        :param timeout: 超时时间,为None使用元素所在页面timeout属性

        :param raise_err: 等待失败时是否报错,为None时根据Settings设置

        :param err_text: 抛出错误时显示的信息

        :return: 是否等待成功

​​​​​​​7.12.6 FrameWaiter(BaseWaiter, ElementWaiter)

属性和方法

功能

__init__(self, frame)

frame: ChromiumFrame对象

  • 15
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

python编程爱好者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值