Created
October 15, 2019 05:30
-
-
Save tai2/ac2e8a321c66ded8fd5e7f3064ac671c to your computer and use it in GitHub Desktop.
CDP Input.insertText using chrome-remote-interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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