Controller

interface Controller

WebView自动化控制器接口(异步版)。

提供了一套全面的API,用于以异步、非阻塞的方式与WebView中的网页内容进行交互。 所有方法都会立即返回一个 Deferred 对象,代表一个未来的计算结果。 你可以通过 .getOrigin().await() 等待结果,或在协程作用域中直接 await()

⚠️ 注意: 此接口中的所有方法都是非阻塞的,可以安全地在任何线程中调用。 框架内部会自动将耗时操作(如JS评估)切换到后台线程,并将结果调度回脚本线程。

Functions

Link copied to clipboard
abstract fun addCookie(scope: CoroutineScope, name: String, value: String, domain: String?, path: String): Deferred<Unit>

异步向当前网页作用域添加一个 Cookie。

Link copied to clipboard
abstract fun back(scope: CoroutineScope): Deferred<Unit>

异步导航到浏览历史中的上一页。

Link copied to clipboard
abstract fun chooseFiles(scope: CoroutineScope, action: () -> Unit, fileChooser: (FileChooserParams?) -> List<ScriptFile>): Deferred<Unit>

异步处理文件选择。会先执行 action(例如点击上传按钮),然后等待WebView弹出文件选择器, 并使用 fileChooser 的返回结果来响应。

Link copied to clipboard
abstract fun clear(scope: CoroutineScope, xpath: String): Deferred<Unit>

异步清空由XPath指定的输入框中的内容。

Link copied to clipboard

异步清空 LocalStorage 中的所有数据。

Link copied to clipboard

异步清空 SessionStorage 中的所有数据。

Link copied to clipboard
abstract fun click(scope: CoroutineScope, xpath: String): Deferred<Unit>

异步模拟用户点击由XPath指定的元素。

Link copied to clipboard
abstract fun contextClick(scope: CoroutineScope, xpath: String): Deferred<Unit>

异步模拟在指定元素上进行右键点击。

Link copied to clipboard

异步删除当前网页下的所有 Cookie。

Link copied to clipboard
abstract fun deleteCookie(scope: CoroutineScope, name: String): Deferred<Unit>

异步删除指定名称的 Cookie。

Link copied to clipboard
abstract fun doubleClick(scope: CoroutineScope, xpath: String): Deferred<Unit>

异步模拟双击指定元素。

Link copied to clipboard
abstract fun downloadFile(scope: CoroutineScope, action: () -> Unit, fileDownloader: (FileDownloaderParams) -> ScriptFile): Deferred<Unit>

异步处理文件下载。会先执行 action(例如点击下载链接),然后等待WebView触发下载请求, 并将文件保存到 fileDownloader 指定的位置。

Link copied to clipboard
abstract fun dragAndDrop(scope: CoroutineScope, sourceXpath: String, targetXpath: String): Deferred<Unit>

异步模拟将一个元素拖拽到另一个元素上。

Link copied to clipboard
abstract fun evaluateJs(scope: CoroutineScope, url: String, repeatable: Boolean): Deferred<String?>

异步加载并执行网络中的JavaScript文件。

Link copied to clipboard
abstract fun evaluateJsFile(scope: CoroutineScope, file: ScriptFile, repeatable: Boolean): Deferred<String?>

异步执行本地存储的JavaScript文件。

Link copied to clipboard
abstract fun executeJsString(scope: CoroutineScope, script: String): Deferred<String?>

异步在当前上下文中执行一段自定义的JavaScript脚本。

Link copied to clipboard
abstract fun forward(scope: CoroutineScope): Deferred<Unit>

异步导航到浏览历史中的下一页。

Link copied to clipboard

异步获取当前网页下所有 Cookie。

Link copied to clipboard
abstract fun getAttribute(scope: CoroutineScope, xpath: String, attributeName: String): Deferred<String?>

异步获取由XPath指定的元素的某个HTML属性值 (Attribute)。

Link copied to clipboard
abstract fun getCookie(scope: CoroutineScope, name: String): Deferred<String?>

异步获取指定名称的 Cookie 值。

Link copied to clipboard
abstract fun getCssValue(scope: CoroutineScope, xpath: String, propertyName: String): Deferred<String?>

异步获取由XPath指定的元素的计算后CSS样式属性值。

Link copied to clipboard

异步获取当前WebView加载的URL。

Link copied to clipboard
abstract fun getElementCount(scope: CoroutineScope, xpath: String): Deferred<Int>

异步获取所有匹配XPath的元素的数量。

Link copied to clipboard

异步从 LocalStorage 中获取指定键的值。

Link copied to clipboard

异步获取当前页面的完整HTML源代码。

Link copied to clipboard
abstract fun getProperty(scope: CoroutineScope, xpath: String, propertyName: String): Deferred<String?>

异步获取由XPath指定的元素的某个 DOM 属性值 (Property)。

Link copied to clipboard
abstract fun getRect(scope: CoroutineScope, xpath: String): Deferred<RectF?>

异步获取元素相对于浏览器视口的位置和尺寸。

Link copied to clipboard

异步从 SessionStorage 中获取指定键的值。

Link copied to clipboard
abstract fun getText(scope: CoroutineScope, xpath: String): Deferred<String?>

异步获取由XPath指定的元素的聚合文本内容 (textContent)。

Link copied to clipboard
abstract fun getTitle(scope: CoroutineScope): Deferred<String?>

异步获取当前页面的标题。

Link copied to clipboard
abstract fun isDisplayed(scope: CoroutineScope, xpath: String): Deferred<Boolean>

异步检查由XPath指定的元素是否在页面上可见。

Link copied to clipboard
abstract fun isPresent(scope: CoroutineScope, xpath: String): Deferred<Boolean>

异步检查由XPath指定的元素是否存在于DOM中。

Link copied to clipboard
abstract fun isSelected(scope: CoroutineScope, xpath: String): Deferred<Boolean>

异步检查表单元素是否被选中。

Link copied to clipboard
abstract fun loadData(scope: CoroutineScope, data: String, mimeType: String?, encoding: String?): Deferred<Unit>

异步使用 'data' scheme URL 将给定的数据加载到此WebView中。

Link copied to clipboard
abstract fun loadDataWithBaseURL(scope: CoroutineScope, baseUrl: String?, data: String, mimeType: String?, encoding: String?, historyUrl: String?): Deferred<Unit>

异步将给定的HTML字符串加载到此WebView中,并允许您指定一个基础URL。

Link copied to clipboard
abstract fun loadUrl(scope: CoroutineScope, url: String, additionalHttpHeaders: Map<String, String>): Deferred<Unit>

异步使用额外的HTTP头加载指定的URL。

Link copied to clipboard
abstract fun navigateTo(scope: CoroutineScope, url: String): Deferred<Unit>

异步导航到指定的网址。

Link copied to clipboard
abstract fun pressKey(scope: CoroutineScope, xpath: String, keySequence: String): Deferred<Unit>

异步模拟在指定元素上按下单个按键或组合键。

Link copied to clipboard
abstract fun reload(scope: CoroutineScope): Deferred<Unit>

异步刷新当前页面。

Link copied to clipboard

异步从 LocalStorage 中移除指定键。

Link copied to clipboard

异步从 SessionStorage 中移除指定键。

Link copied to clipboard
abstract fun scrollBy(scope: CoroutineScope, dx: Int, dy: Int): Deferred<Unit>

异步将整个页面按指定的偏移量进行滚动。

Link copied to clipboard
abstract fun scrollIntoView(scope: CoroutineScope, xpath: String): Deferred<Unit>

异步将指定的元素滚动到可视区域内。

Link copied to clipboard
abstract fun scrollTo(scope: CoroutineScope, x: Int, y: Int): Deferred<Unit>

异步将整个页面滚动到指定的绝对坐标。

Link copied to clipboard
abstract fun selectByValue(scope: CoroutineScope, xpath: String, value: String): Deferred<Unit>

异步根据value属性选择<select>下拉列表中的选项。

Link copied to clipboard
abstract fun selectByVisibleText(scope: CoroutineScope, xpath: String, text: String): Deferred<Unit>

异步根据可见文本内容选择<select>下拉列表中的选项。

Link copied to clipboard
abstract fun sendKeys(scope: CoroutineScope, xpath: String, text: String): Deferred<Unit>

异步在由XPath指定的输入框中输入文本。

Link copied to clipboard
abstract fun setLocalStorageItem(scope: CoroutineScope, key: String, value: String): Deferred<Unit>

异步在 LocalStorage 中设置键值对。

Link copied to clipboard
abstract fun setSessionStorageItem(scope: CoroutineScope, key: String, value: String): Deferred<Unit>

异步在 SessionStorage 中设置键值对。

Link copied to clipboard

异步切换回主文档上下文。

Link copied to clipboard
abstract fun switchToFrame(scope: CoroutineScope, xpath: String): Deferred<Unit>

异步切换到指定的iframe中。要切换到嵌套的iframe,请多次调用此方法。

Link copied to clipboard

异步截取由XPath指定的单个元素的图像。

Link copied to clipboard

异步获取WebView可视区域的截图。

Link copied to clipboard
abstract fun waitForElementPresent(scope: CoroutineScope, xpath: String, timeout: Long): Deferred<Boolean>

异步等待由XPath指定的元素出现在DOM中,直到超时。

Link copied to clipboard
abstract fun waitForElementVisible(scope: CoroutineScope, xpath: String, timeout: Long): Deferred<Boolean>

异步等待由XPath指定的元素变得可见,直到超时。