在生产服务器中使用selenium运行自动化时,我收到以下错误。我的代码在filezila FTP应用程序上:
Error: The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.
at new ServiceBuilder (/home/ec2-user/bseSTP_schemeCode_node/node_modules/selenium-webdriver/chrome.js:161:13)
at Function.getDefaultService (/home/ec2-user/bseSTP_schemeCode_node/node_modules/selenium-webdriver/chrome.js:278:22)
at Function.createSession (/home/ec2-user/bseSTP_schemeCode_node/node_modules/selenium-webdriver/chromium.js:663:49)
at Function.createSession (/home/ec2-user/bseSTP_schemeCode_node/node_modules/selenium-webdriver/chrome.js:240:13)
at createDriver (/home/ec2-user/bseSTP_schemeCode_node/node_modules/selenium-webdriver/index.js:147:33)
at Builder.build (/home/ec2-user/bseSTP_schemeCode_node/node_modules/selenium-webdriver/index.js:712:16)
at startScript (/home/ec2-user/bseSTP_schemeCode_node/script.js:30:6)
at Object.<anonymous> (/home/ec2-user/bseSTP_schemeCode_node/script.js:161:1)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
在本地运行时,它运行良好。
以下是运行脚本的代码:
var webdriver = require("selenium-webdriver");
const { until } = require("selenium-webdriver");
const { By } = require("selenium-webdriver");
// let chromedriver = require("chromedriver");
const util = require("util");
chrome = require('selenium-webdriver/chrome');
// chrome.setDefaultService(new chrome.ServiceBuilder("C:/Vishal/tasks/24-03-2022/bseMaster_Upload_Automation/chromedriver.exe").build());
options = new chrome.Options();
options.addArguments("headless"); // note: without dashes
options.addArguments("disable-gpu");
// console.log(chromedriver.path);
async function startScript() {
// var driver = new webdriver.Builder()
// .withCapabilities(webdriver.Capabilities.chrome())
// .setChromeOptions(options)
// .build();
const driver = new webdriver.Builder()
.forBrowser('chrome').setChromeOptions(options)
.build();
// await driver.manage().window().maximize();
await driver.get("https://www.bsestarmf.in/Index.aspx");
await driver.quit();
}
在服务器上运行代码时出现了什么问题?
谢谢。
听起来你需要在服务器上安装依赖项,比如chromedriver,可能还有Chrome。
您可能在某个时候在本地安装了chromedriver,这可以解释为什么它在本地工作而不在服务器上工作。
我刚刚学习Selenium网络驱动程序,今天我犯了和你相同的错误(幸运的是xD解决了它(。如果你仍然需要一个解决方案,我只想在这里补充我的观点:我不知道你为什么评论:
// let chromedriver = require("chromedriver");
我使用了require("chromedriver");
,但没有将其作为变量,它对我很有效。