uploadFile
透過使用 file
指令,將檔案上傳到 Selenium Standalone 伺服器或其他瀏覽器驅動程式(例如 Chromedriver 或 EdgeDriver)。注意: 只有在您直接使用 Selenium Hub、Chromedriver 或 EdgeDriver 時,才支援此指令。
注意:此指令使用非官方的協定功能,目前僅在 Chrome 和執行 Selenium Grid 時支援。
用法
browser.uploadFile(localPath)
參數
名稱 | 類型 | 詳細資訊 |
---|---|---|
localPath | 字串 | 檔案的本機路徑 |
範例
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()
});