我正在尝试在Electron应用上使用Selenium,并使用以下模块:
"chromedriver": "^78.0.1",
"selenium-webdriver": "^4.0.0-alpha.4",
"electron-builder": "^21.2.0",我在Mac上构建了我的应用程序,Selenium运行得很好。然而,当我在Widows上运行Electron Selenium应用程序时,它找不到chromedriver。
react-electron/node_modules/chromedriver在下面。

当然它没有chromedriver.exe,所以我把chromedriver.exe放到了chromedriver/bin中。然后我重新构建了它,但构建的应用程序不包含chromedriver.exe。如何将chromedriver.exe打包到已构建的应用程序中?
我感谢你的帮助。
发布于 2019-11-02 00:45:26
我找到了解决方案。我把chromedriver.exe放到了node_modules/chromedriver/lib/chromedriver中。
我可以检查它是在win-unpacked/resources/app.asar.unpacked/node_modules/chromedriver/lib/chromedriver/chromedriver.exe中复制的
当应用程序运行时,chromedriver可能会在C:\Users\user\AppData\Local\Programs\MyApp\resources\app.asar.unpacked\node_modules\chromedriver\lib\chromedriver\chromedriver.exe中被罚款
我可以像这样得到驱动程序路径。
const chromedriver = require('chromedriver');
async getDriverPath() {
let driverPath:string = this.chromedriver.path;
driverPath = await driverPath.replace('app.asar','app.asar.unpacked');
log.info("this.driverPath " + driverPath);
return driverPath;
}另外,我像这样设置了驱动程序路径。
const webdriver = require('selenium-webdriver');
const {Builder} = webdriver;
let my_driver;
async startChrome() {
const driverPath = await this.getDriverPath();
const service = new chrome.ServiceBuilder(driverPath).build();
chrome.setDefaultService(service);
my_driver = new Builder().forBrowser('chrome').build();
}我希望这能对某些人有所帮助。
https://stackoverflow.com/questions/58647737
复制相似问题