跳到主要内容

上传文件

通过使用file命令将文件上传到Selenium Standalone服务器或其他浏览器驱动程序(例如Chromedriver或EdgeDriver)。 _注意:_此命令仅在您直接使用Selenium Hub、Chromedriver或EdgeDriver时才受支持。

__注意:__此命令使用的是非官方协议功能,目前仅在Chrome浏览器和运行Selenium Grid时支持。

用法
browser.uploadFile(localPath)
参数
名称类型详情
localPathstring文件的本地路径
示例
uploadFile.js
import path from 'node:path'

it('should upload a file', async () => {
await browser.url('https://the-internet.herokuapp.com/upload')

const filePath = '/path/to/some/file.png'
const remoteFilePath = await browser.uploadFile(filePath)

await $('#file-upload').setValue(remoteFilePath)
await $('#file-submit').click()
});
返回
  • <String> return: 远程URL

Welcome! How can I help?

WebdriverIO AI Copilot