Google chrome 输入未调度的击键事件
试图通过远程调试协议向headless chrome发送回车键。这是源代码。感谢您的帮助。它似乎不适用于Chrome69。除了windowsVirtualKeyCode:13之外,我还尝试了keyIdentifier:'U+000D',keyIdentifier:'Enter'和key:'\u000d'Google chrome 输入未调度的击键事件,google-chrome,google-chrome-devtools,selenium-chromedriver,chromium,remote-debugging,Google Chrome,Google Chrome Devtools,Selenium Chromedriver,Chromium,Remote Debugging,试图通过远程调试协议向headless chrome发送回车键。这是源代码。感谢您的帮助。它似乎不适用于Chrome69。除了windowsVirtualKeyCode:13之外,我还尝试了keyIdentifier:'U+000D',keyIdentifier:'Enter'和key:'\u000d' const CDP = require("chrome-remote-interface") const chromeLauncher = require("chrome-launcher")
const CDP = require("chrome-remote-interface")
const chromeLauncher = require("chrome-launcher")
const getPort = require("get-port")
const R = require("rambdax")
const chromeFlags = [
"--disable-gpu",
"--disable-sync",
"--no-first-run",
"--headless",
"--window-size=1366,768"
]
const main = async () => {
try{
const port = await getPort()
const chrome = await chromeLauncher.launch({
chromeFlags,
port,
})
const client = await CDP({ port })
const { Page, Runtime, Input } = client
await Promise.all([
Page.enable(),
Runtime.enable(),
])
await Page.navigate({ url : 'https://www.google.com' })
await Page.loadEventFired()
await R.delay(1000)
await Input.dispatchKeyEvent({ type: 'char', text: 't' })
await R.delay(200)
await Input.dispatchKeyEvent({ type: 'char', text: 'e' })
await R.delay(200)
await Input.dispatchKeyEvent({ type: 'char', text: 's' })
await R.delay(200)
await Input.dispatchKeyEvent({ type: 'char', text: 't' })
await R.delay(200)
await Input.dispatchKeyEvent({ type: 'rawKeyDown', windowsVirtualKeyCode: 13 })
await R.delay(3000)
}catch(err){
console.log(err)
}
}
看,上面的代码也是从哪里来的。使用以下工程:
await Input.dispatchKeyEvent({ type: 'char', text: "\r" })