-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I upload files? #164
Comments
Hm, do you mean how to submit a form which include file upload using the CDP? Specifically how to handle the In that case, you can use const CDP = require('chrome-remote-interface');
CDP(async (client) => {
try {
const {DOM, Runtime} = client;
// fetch the file input node
const {root} = await DOM.getDocument();
const {nodeId: myFileId} = await DOM.querySelector({
nodeId: root.nodeId,
selector: '#myFile'
});
// fill the file input
await DOM.setFileInputFiles({
nodeId: myFileId,
files: ['/tmp/foo', '/tmp/bar']
});
// submit the form
await Runtime.evaluate({
expression: `document.getElementById('myForm').submit()`
});
} catch (err) {
console.error(err);
} finally {
client.close();
}
}).on('error', (err) => {
console.error(err);
}); |
Thank you! Your answer is perfect! |
May I ask how to access documents in an iframe, such as accessing a div element that exists in the iframe
May I ask how to access documents in an iframe, such as accessing a div element that exists in the iframe |
How do I upload files?
The text was updated successfully, but these errors were encountered: