Skip to content

页面命令

xpage 提供 35+ 统一页面命令,所有操作通过 (page, args) => Promise<result> 接口执行。

导航命令

命令描述参数
goto导航到 URLurl, waitUntil?, timeout?
goBack后退
goForward前进
reload刷新页面
title获取页面标题
url获取当前 URL

交互命令

命令描述参数
click点击元素selector, timeout?, force?
fill填充输入框selector, value, timeout?
type逐字输入selector, text, delay?
press按键selector, key
hover悬停selector, timeout?
scroll滚动selector?, x?, y?
select选择选项selector, value
check勾选复选框selector
dblclick双击selector, timeout?

查询命令

命令描述参数
queryCSS 选择器查询selector
find按文本查找text, tag?, exact?
html获取 HTMLselector?, clean?
text获取文本内容selector?
textContent获取元素文本selector
inputValue获取输入值selector
getAttribute获取属性selector, name

等待命令

命令描述参数
waitForSelector等待元素出现selector, timeout?, state?
wait等待毫秒数timeout

截图命令

命令描述参数
screenshot截图到文件path?, fullPage?, type?, quality?
screenshotBase64截图为 Base64fullPage?, type?

结构与无障碍命令

命令描述参数
structure页面结构提取selector?, maxDepth?
a11y无障碍树selector?, format?
snapshotARIA 快照selector?

执行命令

命令描述参数
evaluate执行 JS 表达式expression
evaluateRaw执行异步 JSscript

命令链

使用 executeCommandChain 链式执行多个命令:

typescript
import { executeCommandChain } from '@dyyz1993/xpage';

const result = await executeCommandChain(page, `
  goto url=https://example.com &&
  title &&
  text selector=body &&
  screenshot path=example.png
`);

基于 MIT 许可发布