我試圖用 javascript 語言設定帶有硒的 chrome 二進制檔案的二進制路徑。不幸的是,我在 javascript 方面的知識是有限的,我在嘗試這樣做時遇到了一個錯誤,盡管我努力了,但我無法解決。所以事不宜遲,我現在將分享我的問題,希望比我更懂javascript的人能幫助我一些背景知識:我在firebase中觸發一個函式可以運行,在這個函式內部,我正在嘗試創建一個硒網路驅動程式。為此:
我需要做這些事情:
chromedriver --> 在 linux 系統上作業(位于 functions 專案檔案夾內)?
位于這臺機器上的 chrome 瀏覽器二進制檔案 ? 3.then,我需要創建一個 chrome 選項物件。一個。添加一個引數,所以它會是無頭的。? b. 使用 chrome 二進制檔案的路徑設定它。?
最后,使用我創建的選項創建一個 chrome 驅動程式
目前,我處于 ??3.b 階段
由于我對javascript的了解不足而出現的錯誤是錯誤: TypeError:對常量變數的賦值。
這是導致此錯誤的原因
這是我的代碼:
exports.initializedChromeDriver = functions.https.onRequest((request, response) => {
async function start_chrome_driver() {
try {
functions.logger.info('Hello logs!', {structuredData: true});
console.log("did enter the function")
const google_site = "https://www.gooogle.com";
const { WebDriver } = require('selenium-webdriver');
const {Builder, By} = require('selenium-webdriver');
console.log("will try to initialzed chrome");
let chrome = require('selenium-webdriver/chrome');
console.log("did initialzed chrome");
var chrome_options = new chrome.Options()
console.log("will try to set the chrome binary Path");
functions.logger.info('new chrome.Options()', {structuredData: true});
chrome_options = chrome_options.setChromeBinaryPath(path="/usr/bin/google-chrome");// <------- THIS IS THE LINE THAT RISE THE ERROR!
console.log("did setChromeBinaryPath");
chrome_options.addArguments("--headless");
let buillder = new Builder().forBrowser('chrome');
functions.logger.info(' did new Builder().forBrowser(chrome)', {structuredData: true});
const google_site = 'https://wwww.google.com'
await driver.get(google_site);
functions.logger.info('driver did open google site', {structuredData: true});
return "succ loading google"
}
catch (err) {
console.log('did catch')
console.error(err);
return "error loading google";
}
}
const p = start_chrome_driver().then((value,reject) => {
const dic = {};
dic['status'] = 200;
dic['data'] = {"message": value};
response.send(dic);
});
這是firebase函式日志中此代碼后面的錯誤:

我試圖將 chrome_options 物件更改為 var/let,并在 web 中尋找答案,但是在一次又一次地部署之后。我覺得是時候換個角度了,任何幫助都可以。
uj5u.com熱心網友回復:
您在這里有一個不必要的分配 (path=...)
chrome_options = chrome_options.setChromeBinaryPath(path="/usr/bin/google-chrome");
只需洗掉分配給path
chrome_options = chrome_options.setChromeBinaryPath("/usr/bin/google-chrome");
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/417737.html
標籤:
上一篇:硒難以找到元素
