electron 如何获取页面中的元素

新手上路,请多包涵

在 electron 下我使用了

win = new BrowserWindow({width: 800, height: 600})
win.loadURL("https://github.com/login");

win.webContents.on('dom-ready', () => {
       new Login().init();
})

我如何获取该页面的元素
我尝试了win.document.getElementById('login_field'); 然后报错了,
后来尝试用remote 模块,写了一个类叫login

const currentWeb = require("electron").remote.getCurrentWebContents;

class Login {
    constructor() {

    }
    init() {
        let userInput =  document.getElementById('login_field');
        userInput.value = '123123';
    }
}


module.exports = Login;

同样的报错了,

clipboard.png

阅读 9.7k
1 个回答
新手上路,请多包涵

const XXX = document.querySelector("#XXX");

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题