Przejdź do głównej treści

uploadFile

Przesyła plik na serwer Selenium Standalone lub inny sterownik przeglądarki (np. Chromedriver lub EdgeDriver) za pomocą komendy file. Uwaga: ta komenda jest obsługiwana tylko jeśli używasz Selenium Hub, Chromedriver lub EdgeDriver bezpośrednio.

Uwaga: ta komenda używa nieoficjalnej funkcji protokołu, która jest obecnie obsługiwana tylko w Chrome i podczas uruchamiania Selenium Grid.

Użycie
browser.uploadFile(localPath)
Parametry
NazwaTypSzczegóły
localPathstringlokalna ścieżka do pliku
Przykład
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()
});
Zwraca
  • <String> return: zdalny URL

Welcome! How can I help?

WebdriverIO AI Copilot