qt4w package¶
Submodules¶
qt4w.util module¶
QT4W公共库
-
exception
qt4w.util.
ControlAmbiguousError
¶ -
找到多个控件
-
exception
qt4w.util.
ControlNotFoundError
¶ -
Web元素未找到
-
class
qt4w.util.
Deprecated
(new_func)¶ 基类:
object
废弃函数包装
-
class
qt4w.util.
EnumKeyCode
¶ 基类:
object
按键定义
-
A
= ('KeyA', 65)¶
-
ALT
= ('Alt', 18)¶
-
B
= ('KeyB', 66)¶
-
BACKSPACE
= ('Backspace', 8)¶
-
C
= ('KeyC', 67)¶
-
CTRL
= ('Control', 17)¶
-
D
= ('KeyD', 68)¶
-
DELETE
= ('Delete', 46)¶
-
DOWN
= ('ArrowDown', 40)¶
-
E
= ('KeyE', 69)¶
-
END
= ('End', 35)¶
-
ENTER
= ('Enter', 13)¶
-
ESC
= ('Escape', 27)¶
-
F
= ('KeyF', 70)¶
-
F1
= ('F1', 112)¶
-
F10
= ('F10', 121)¶
-
F11
= ('F11', 122)¶
-
F12
= ('F12', 123)¶
-
F2
= ('F2', 113)¶
-
F3
= ('F3', 114)¶
-
F4
= ('F4', 115)¶
-
F5
= ('F5', 116)¶
-
F6
= ('F6', 117)¶
-
F7
= ('F7', 118)¶
-
F8
= ('F8', 119)¶
-
F9
= ('F9', 120)¶
-
G
= ('KeyG', 71)¶
-
H
= ('KeyH', 72)¶
-
HOME
= ('Home', 36)¶
-
I
= ('KeyI', 73)¶
-
INSERT
= ('Insert', 45)¶
-
J
= ('KeyJ', 74)¶
-
K
= ('KeyK', 75)¶
-
L
= ('KeyL', 76)¶
-
LEFT
= ('ArrowLeft', 37)¶
-
M
= ('KeyM', 77)¶
-
N
= ('KeyN', 78)¶
-
O
= ('KeyO', 79)¶
-
P
= ('KeyP', 80)¶
-
PAGEDOWN
= ('PageDown', 34)¶
-
PAGEUP
= ('PageUp', 33)¶
-
Q
= ('KeyQ', 81)¶
-
R
= ('KeyR', 82)¶
-
RIGHT
= ('ArrowRight', 39)¶
-
S
= ('KeyS', 83)¶
-
SHIFT
= ('Shift', 16)¶
-
T
= ('KeyT', 84)¶
-
TAB
= ('Tab', 9)¶
-
U
= ('KeyU', 85)¶
-
UP
= ('ArrowUp', 38)¶
-
V
= ('KeyV', 86)¶
-
W
= ('KeyW', 87)¶
-
X
= ('KeyX', 88)¶
-
Y
= ('KeyY', 89)¶
-
Z
= ('KeyZ', 90)¶
-
static
init
()¶
-
static
parse
(text)¶
-
-
class
qt4w.util.
Frame
(_id, name, url)¶ 基类:
object
frame element
-
add_child
(frame)¶ 添加子frame
-
find_child_frame
(name, url)¶ 查找子frame
-
id
¶
-
name
¶
-
url
¶
-
-
class
qt4w.util.
FrameSelector
(webdriver, root_frame)¶ 基类:
object
Frame定位
-
get_frame_by_xpath
(frame_xpaths)¶ 根据XPath对象查找frame
参数: frame_xpaths (list) – frame的xpath数组 返回: Frame object
-
-
exception
qt4w.util.
JavaScriptError
(frame, err_msg)¶ 基类:
exceptions.RuntimeError
执行JavaScript报错
-
frame
¶ 发生JS异常的frame
-
message
¶
-
-
class
qt4w.util.
LazyDict
(getter, setter=None, lister=None)¶ 基类:
object
类字典容器,本身不存储数据,只在需要时调用相应函数实现读写操作
-
exception
qt4w.util.
QT4WRuntimeError
¶ 基类:
exceptions.RuntimeError
QT4W运行时错误
-
message
¶ 解决python3上没有message属性的问题
-
-
class
qt4w.util.
Rect
(rect)¶ 基类:
object
控件坐标区域
-
Height
¶
-
Left
¶
-
Top
¶
-
Width
¶
-
height
¶ 高度
-
left
¶ 左上角横坐标
-
top
¶ 左上角纵坐标
-
width
¶ 宽度
-
-
exception
qt4w.util.
TimeoutError
¶ -
超时错误
-
class
qt4w.util.
WebElementAttributes
(getter, setter=None, lister=None)¶ -
供WebElement的Attributes属性使用的类字典容器
-
class
qt4w.util.
WebElementStyles
(getter, setter=None, lister=None)¶ -
供WebElement的Styles属性使用的类字典容器
-
qt4w.util.
encode_wrap
(func)¶ 处理函数返回值编码
-
qt4w.util.
general_encode
(s)¶ 字符串通用编码处理 python2 => utf8 python3 => unicode
-
qt4w.util.
lazy_init
(func)¶ 懒初始化
-
qt4w.util.
unicode_decode
(s)¶ 将字符串解码为unicode编码
qt4w.webcontrols module¶
WebPage、WebElement接口类
-
class
qt4w.webcontrols.
ControlContainer
¶ 基类:
object
控件容器基类
-
Controls
¶
-
control
(name)¶ 获取控件实例
-
get_metis_view
()¶ 返回MetisView
-
ui_control_type
= None¶
-
ui_map
= {}¶
-
updateLocator
(locators)¶ 更新控件定位参数
参数: locators (dict) – 定位参数,格式是 {‘控件名’:{‘type’:控件类, 控件类的参数dict列表}, …}
-
update_ui_map
(ui_map)¶ 从指定的ui_map中更新控件定义
-
-
class
qt4w.webcontrols.
FrameElement
(root, locator)¶ 基类:
qt4w.webcontrols.WebElement
frame/iframe元素
-
FramePage
¶
-
framepage
¶ frame中包含的WebPage
-
-
class
qt4w.webcontrols.
IWebElement
¶ 基类:
object
WebElement接口定义
-
Attributes
¶
-
BoundingRect
¶ 元素位置信息
-
Displayed
¶
-
InnerHtml
¶
-
InnerText
¶
-
attributes
¶ 元素的属性集合
-
click
(x_offset=None, y_offset=None)¶ 点击元素,默认点击元素中点
参数: - x_offset (int或float) – 距离控件区域左上角的横向偏移。
- y_offset (int或float) – 距离控件区域左上角的纵向偏移。
-
displayed
¶ 元素是否显示
-
double_click
(x_offset=None, y_offset=None)¶ 双击元素,默认双击元素中点
参数: - x_offset (int或float) – 距离控件区域左上角的横向偏移。
- y_offset (int或float) – 距离控件区域左上角的纵向偏移。
-
drag
(x, y)¶ 拖放元素到指定位置
参数: - x (int或float) – 拖放终点距离起点的横向偏移。
- y (int或float) – 放终点距离起点的纵向偏移。
-
exist
()¶ 元素是否存在
-
focused
¶ 元素是否有焦点
-
getElement
(*args, **kwargs)¶
-
getElements
(*args, **kwargs)¶
-
get_element
(locator)¶ 在当前元素的子孙元素中查找元素,返回第一个匹配的元素
参数: locator (string或XPath) – 元素的xpath路径
-
get_elements
(locator)¶ 在当前元素的子孙元素中查找元素,返回包含所有匹配的元素的列表
参数: locator (string或XPath) – 元素的xpath路径
-
hover
(x_offset=None, y_offset=None)¶ 鼠标悬停
参数: - x_offset (int或float) – 距离控件区域左上角的横向偏移。
- y_offset (int或float) – 距离控件区域左上角的纵向偏移。
-
inner_html
¶ 元素所包含的HTML代码
-
inner_text
¶ 元素所包含的文本
-
long_click
(x_offset=None, y_offset=None, duration=1)¶ 长按元素
参数: - x_offset (int/float) – 距离控件区域左上角的横向偏移
- y_offset (int/float) – 距离控件区域左上角的纵向偏移
- duration (int/float) – 按住的持续时间
-
page
¶ 元素所在WebPage
-
rect
¶ 元素位置信息
-
right_click
(x_offset=None, y_offset=None)¶ 右击元素,默认右击元素中点
参数: - x_offset (int或float) – 距离控件区域左上角的横向偏移。
- y_offset (int或float) – 距离控件区域左上角的纵向偏移。
-
screenshot
()¶ 设置控件截图
-
scroll
(x, y)¶ 滚动元素
参数: - x (int) – 横向滚动的偏移,负值向左,正值向右
- y (int) – 纵向滚动的偏移,负值向上,正值向下
-
sendKeys
(*args, **kwargs)¶
-
send_keys
(keys)¶ 发送按键
参数: keys (string) – 发送的按键
-
set_focus
()¶ 设为焦点
-
styles
¶ 元素的样式集合
-
visible
¶ 元素是否视觉可见
-
wait_for_attribute
(name, value, timeout=10, interval=0.5)¶ 暂停程序执行,直到当前元素的指定属性变为特定值
参数: - name (string) – 要等待的属性名
- value (string) – 要等待的属性值
:param timeout:超时时间 :type timeout: int或float :param interval:重试间隔时间 :type interval:int或float
-
wait_for_style
(name, value, timeout=10, interval=0.5)¶ 暂停程序执行,直到当前元素的指定样式变为特定值
参数: - name (string) – 要等待的样式名
- value (string) – 要等待的样式值
:param timeout:超时时间 :type timeout: int或float :param interval:重试间隔时间 :type interval:int或float
-
wait_for_text
(value, timeout=10, interval=0.5)¶ 暂停程序执行,直到当前元素的InnerText变为特定值
参数: - value (string) – 要等待的特定值
- timeout (int或float) – 超时时间
:param interval:重试间隔时间 :type interval: int或float
-
wait_for_visible
(timeout=10, interval=0.5)¶ 等待控件可见
参数: timeout (float) – 超时时间 :param interval:查询间隔时间 :type interval: float
-
-
class
qt4w.webcontrols.
IWebPage
¶ 基类:
object
WebPage接口定义
-
ReadyState
¶
-
Title
¶
-
Url
¶
-
accessible_object
¶ accessible对象
-
activate
()¶ 激活承载页面的窗口
-
browser_type
¶ 浏览器类型
-
close
()¶ 关闭承载页面的窗口
页面cookie
-
execScript
(*args, **kwargs)¶
-
exec_script
(script)¶ 在页面中执行JavaScript代码,并返回直接结果
参数: script (string) – 要执行的代码
-
getElement
(*args, **kwargs)¶
-
getElements
(*args, **kwargs)¶
-
get_element
(locator)¶ 在页面中查找元素,返回第一个匹配的元素
参数: locator (string或XPath) – 元素的xpath路径
-
get_elements
(locator)¶ 在页面中查找元素,返回包含所有匹配的元素的列表
参数: locator (string或XPath) – 元素的xpath路径
-
pull_down_refresh
()¶ 下拉刷新
-
pull_up_refresh
()¶ 上拉刷新
-
read_console_log
(timeout=None)¶ 读取一条console.log输出的日志
参数: timeout (int) – 读取日志的超时时间,为None表示不会超时
-
ready_state
¶ 页面状态
-
release
()¶ 释放占用的资源
-
screenshot
()¶ 获取page页面截图
-
scroll
(x, y)¶ 滚动
参数: - x (int) – 横向滚动的偏移,负值向左,正值向右
- y (int) – 纵向滚动的偏移,负值向上,正值向下
-
title
¶ 页面标题
-
upload_file
(file_path)¶ 上传文件
参数: file_path (str) – 文件路径
-
url
¶ 页面url
-
waitForReady
(*args, **kwargs)¶
-
wait_for_ready
(timeout=60)¶ 等待页面状态变为ready
参数: timeout (int) – 超时时间
-
-
class
qt4w.webcontrols.
InputElement
(root, locator)¶ 基类:
qt4w.webcontrols.WebElement
input元素
-
value
¶ 当前的value
-
-
class
qt4w.webcontrols.
MetisView
(page_or_elem)¶ 基类:
object
实现IMetisView接口
-
click
(offset_x=None, offset_y=None)¶ 点击 :param offset_x: 相对于该控件的坐标offset_x,百分比( 0 -> 1 ),不传入则默认该控件的中央 :type offset_x: float|None :param offset_y: 相对于该控件的坐标offset_y,百分比( 0 -> 1 ),不传入则默认该控件的中央 :type offset_y: float|None
-
double_click
(offset_x=None, offset_y=None)¶ 双击
-
long_click
(offset_x=None, offset_y=None)¶ 长按
-
os_type
¶ 系统类型,例如”android”,”ios”,”pc”
-
rect
¶ 元素相对坐标(x, y, w, h)
-
screenshot
()¶ 当前容器的区域截图 :return: PIL.image
-
send_keys
(text)¶ 发送可见字符按键
参数: text (string) – 要输入的文本
-
-
class
qt4w.webcontrols.
SelectElement
(root, locator)¶ 基类:
qt4w.webcontrols.WebElement
select元素
-
options
¶ 返回所有选项列表
-
selection
¶ 当前选择项
-
-
class
qt4w.webcontrols.
UIListBase
(root, locator)¶ 基类:
object
List控件基类
-
filter
(condition)¶ 根据条件过滤,找到满足条件的项即返回,如果找不到则抛出异常
参数: condition (dict) – 过滤条件
-
ui_control_type
= None¶
-
-
class
qt4w.webcontrols.
WebElement
(root, locator)¶ 基类:
qt4w.webcontrols.ControlContainer
,qt4w.webcontrols.IWebElement
IWebElement实现
-
BoundingRect
¶ 元素位置信息
-
attributes
¶ 元素的属性集合
-
click
(x_offset=None, y_offset=None, highlight=True)¶ 点击元素,默认点击元素中点
参数: - x_offset (int或float) – 距离控件区域左上角的横向偏移。
- y_offset (int或float) – 距离控件区域左上角的纵向偏移。
- highlight (bool) – 是否高亮元素
-
displayed
¶
-
double_click
(x_offset=None, y_offset=None)¶ 双击元素,默认双击元素中点
参数: - x_offset (int或float) – 距离控件区域左上角的横向偏移。
- y_offset (int或float) – 距离控件区域左上角的纵向偏移。
-
drag
(x, y)¶ 拖放元素到指定位置
参数: - x (int或float) – 拖放终点距离起点的横向偏移。
- y (int或float) – 放终点距离起点的纵向偏移。
-
exist
()¶ 元素是否存在
-
focused
¶
-
get_element
(locator, elem_cls=None)¶ 在当前元素的子孙元素中查找元素,返回第一个匹配的元素
参数: locator (string或XPath) – 元素的xpath路径 Paran elem_cls: 返回的元素类型
-
get_elements
(locator, elem_cls=None)¶ 在当前元素的子孙元素中查找元素,返回包含所有匹配的元素的列表
参数: locator (string或XPath) – 元素的xpath路径 Paran elem_cls: 返回的元素类型
-
highlight
(*args, **kwargs)¶
-
hover
(x_offset=None, y_offset=None)¶ 鼠标悬停
参数: - x_offset (int或float) – 距离控件区域左上角的横向偏移。
- y_offset (int或float) – 距离控件区域左上角的纵向偏移。
-
inner_html
¶
-
inner_text
¶
-
long_click
(x_offset=None, y_offset=None, duration=1)¶ 长按元素
参数: - x_offset (int/float) – 距离控件区域左上角的横向偏移
- y_offset (int/float) – 距离控件区域左上角的纵向偏移
- duration (int/float) – 按住的持续时间
-
page
¶ 元素所在WebPage
-
post_init
()¶ 窗口类自定义的初始化逻辑
-
rect
¶
-
right_click
(x_offset=None, y_offset=None)¶ 右击元素,默认右击元素中点
参数: - x_offset (int或float) – 距离控件区域左上角的横向偏移。
- y_offset (int或float) – 距离控件区域左上角的纵向偏移。
-
screenshot
()¶ 设置控件截图
-
scroll
(x, y)¶ 滚动元素
参数: - x (int) – 横向滚动的偏移,负值向左,正值向右
- y (int) – 纵向滚动的偏移,负值向上,正值向下
-
send_keys
(keys)¶ 发送按键
参数: keys (string) – 发送的按键
-
set_focus
()¶ 设为焦点
-
styles
¶ 元素的样式集合
-
ui_control_type
¶ WebElement
的别名
-
visible
¶ 元素是否视觉可见
-
wait_for_attribute
(name, value, timeout=10, interval=0.5)¶ 暂停程序执行,直到当前元素的指定属性变为特定值
参数: - name (string) – 要等待的属性名
- value (string) – 要等待的属性值
:param timeout:超时时间 :type timeout: int或float :param interval:重试间隔时间 :type interval:int或float
-
wait_for_style
(name, value, timeout=10, interval=0.5)¶ 暂停程序执行,直到当前元素的指定样式变为特定值
参数: - name (string) – 要等待的样式名
- value (string) – 要等待的样式值
:param timeout:超时时间 :type timeout: int或float :param interval:重试间隔时间 :type interval:int或float
-
wait_for_text
(text, timeout=10, interval=0.5)¶ 暂停程序执行,直到当前元素的InnerText变为特定值
参数: - text (string) – 要等待的特定值
- timeout (int或float) – 超时时间
:param interval:重试间隔时间 :type interval: int或float
-
wait_for_value
(value, timeout=10, interval=0.5)¶ 暂停程序执行,直到当前元素的InnerText变为特定值
参数: - value (string) – 要等待的特定值
- timeout (int或float) – 超时时间
:param interval:重试间隔时间 :type interval: int或float
-
wait_for_visible
(timeout=10, interval=0.5)¶ 等待控件可见
参数: timeout (float) – 超时时间 :param interval:查询间隔时间 :type interval: float
-
-
class
qt4w.webcontrols.
WebPage
(webview_or_webpage, locator=None, wait_for_ready=True)¶ 基类:
qt4w.webcontrols.ControlContainer
,qt4w.webcontrols.IWebPage
IWebPage接口实现
-
activate
()¶ 激活承载页面的窗口
-
browser_type
¶ 浏览器类型
-
close
()¶ 关闭承载页面的窗口
页面cookie
-
exec_script
(**kwargs)¶
-
get_element
(locator, elem_cls=None)¶ 在页面中查找元素,返回第一个匹配的元素
参数: locator (string或XPath) – 元素在当前页面的xpath路径 Paran elem_cls: 返回的元素类型
-
get_elements
(locator, elem_cls=None)¶ 在页面中查找元素,返回包含所有匹配的元素的列表
参数: locator (string或XPath) – 元素的xpath路径 Paran elem_cls: 返回的元素类型
-
pull_down_refresh
()¶ 下拉刷新
-
pull_up_refresh
()¶ 上拉刷新
-
read_console_log
(timeout=None)¶ 读取一条console.log输出的日志
参数: timeout (int) – 读取日志的超时时间,为None表示不会超时
-
ready_state
¶ 页面状态
-
release
()¶ 释放占用的资源
-
screenshot
()¶ 获取page页面截图
返回: PIL.Image
-
scroll
(x, y)¶ 滚动
参数: - x (int) – 横向滚动的偏移,负值向左,正值向右
- y (int) – 纵向滚动的偏移,负值向上,正值向下
-
title
¶ 页面标题
-
ui_control_type
¶ WebElement
的别名
-
upload_file
(file_path)¶ 上传文件
参数: file_path (str) – 文件路径
-
url
¶ 页面url
-
wait_for_ready
(timeout=60)¶ 等待页面状态变为ready
参数: timeout (int) – 超时时间
-
-
qt4w.webcontrols.
ui_list
(control_cls)¶ 列表类型