I spent hours trying to figure out how to solve the following.
I am automating a test case with Playwright – JavaScript where I have to upload an image but it gives me all kinds of errors, the last one I am trying to test is with the documentation uploaded in playwright.dev
Test:
const path = require(‘path’);
import { test, expect } from ‘@playwright/test’;
test("s", async ({ page }) => {
await page.goto('https://www.transfernow.net/es');
await page.getByRole('button', { name: 'Inicio' }).click();
await page.getByRole('button', { name: 'Inicio' }).first().setInputFiles(path.join(__dirname, 'images.png'));
});
Error:
Error: locator.setInputFiles: Error: Node is not an HTMLInputElement
Call log:
- waiting for getByRole(‘button’, { name: ‘Inicio’ }).first()
- locator resolved to …
How i can fix this?.
2
Answers
As mentioned in the comment , please make sure that you are using the setInputFiles() method on an input element of type "file" that is visible and enabled.
Indicates that
setInputFiles
method is being called on a node that is not an HTML input element of typefile
. In order to fix this, you need to ensure that you are targeting the correctfile
input element on the webpage.Refer the code below for reference :