WebSelector.text - 文本约束
WebSelector.text
通过文本内容约束。
声明
node.web_selector(window):text(val)
参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| val | string | 是 | 文本内容,支持正则表达式 |
返回值
| 类型 | 说明 |
|---|---|
| WebSelector | 返回自身,支持链式调用 |
说明
支持两种匹配模式:
- 精确匹配:直接传入字符串
- 正则匹配:使用
/正则表达式/格式(JS 正则语法)
待实现
该接口正在开发中。
示例
local node = require("node")
local window = node.web_window("http://www.example.com")
-- 精确匹配
local n = node.web_selector(window):text("登录"):find()
-- 正则匹配:包含"百度"的文本
local n2 = node.web_selector(window):text("/百度/"):find()
-- 正则匹配:匹配数字+元
local n3 = node.web_selector(window):text("/\\d+元/"):find()
AScript 对应
# AScript (Python)
from ascript.android.node import WebSelector
from ascript.android.ui import WebWindow
window = WebWindow("http://www.example.com")
# 精确匹配
node = WebSelector(window).text("百度一下").find()
# 正则匹配
node = WebSelector(window).text("/百度/").find()