javascript - Selector resolved to hidden - playwright and <input> with display: none. Can anyone know how to make

Selector has display: none. Im using playwright to send file like this:await page.setInputFiles(

Selector has display: none.

Im using playwright to send file like this:

await page.setInputFiles(
'//*[@id="root"]/div/div/main/div/div[2]/div[3]/input',
file);

And this is error I get:

waiting for selector "//*[@id="root"]/div/div/main/div/div[2]/div[3]/input" selector resolved to hidden

Do you know how to make it work? Thanks

Selector has display: none.

Im using playwright to send file like this:

await page.setInputFiles(
'//*[@id="root"]/div/div/main/div/div[2]/div[3]/input',
file);

And this is error I get:

waiting for selector "//*[@id="root"]/div/div/main/div/div[2]/div[3]/input" selector resolved to hidden

Do you know how to make it work? Thanks

Share Improve this question edited Sep 1, 2021 at 7:08 demouser123 4,28412 gold badges52 silver badges87 bronze badges asked Aug 31, 2021 at 15:43 AKKAKK 1461 gold badge2 silver badges5 bronze badges 1
  • 1 Are you using the latest Playwright version? If I remember correctly a related bug got fixed in the last few releases. If not, I remend to create a bug on GitHub with a repro: github./microsoft/playwright – Max Schmitt Commented Sep 6, 2021 at 10:56
Add a ment  | 

2 Answers 2

Reset to default 1

You need to change the display property of the element using the evaluate method.

let inputFileSelector = await page.$('xpath=//*[@id="root"]/div/div/main/div/div[2]/div[3]/input');
await inputFileSelector.evaluate((el) => el.style.display = 'inline'); // or inherit

Or you can also do this directly as

await page.evaluate(() => { document.querySelector('mySelector').style.display = 'inline'; });

When your input element is hidden, file chooser dialog is typically triggered by some action. You can start listening to the filechooser event on page and trigger the file selection (typically press some button in the ui that brings up file selection dialog). This use case is discussed in the doc, last paragraph: https://playwright.dev/docs/input#upload-files.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744757851a4591987.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信