Skip to content

Instantly share code, notes, and snippets.

@tai2
Created October 15, 2019 05:30
Show Gist options
  • Save tai2/ac2e8a321c66ded8fd5e7f3064ac671c to your computer and use it in GitHub Desktop.
Save tai2/ac2e8a321c66ded8fd5e7f3064ac671c to your computer and use it in GitHub Desktop.
CDP Input.insertText using chrome-remote-interface
const CDP = require('chrome-remote-interface')
async function example() {
let client;
try {
client = await CDP()
const {Page, Input, DOM} = client
await Page.enable()
await DOM.enable()
await Page.navigate({url: 'https://getbootstrap.com/docs/4.3/components/forms/'})
await Page.loadEventFired()
const document = await DOM.getDocument()
const emailInputNode = await DOM.querySelector({nodeId: document.root.nodeId, selector: 'input[type=email]'})
await DOM.focus({ nodeId: emailInputNode.nodeId})
//await Input.dispatchKeyEvent({ type: 'char', text: 'あい' })
await Input.insertText({text: 'あいうえおかきくけこ'})
} catch (err) {
console.error(err)
} finally {
if (client) {
await client.close()
}
}
}
example()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment