admin管理员组文章数量:1393090
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
2 Answers
Reset to default 1You 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.
本文标签:
版权声明:本文标题:javascript - Selector resolved to hidden - playwright and <input> with display: none. Can anyone know how to make 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744757850a2623568.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论