我对使用.net的selenium有一个问题,需要您的帮助。
我正在使用.net 5,并试图在Linux上运行Selenium,并获得"System.ComponentModel.Win32Exception No这样的文件或目录“错误。我以为chromedriver文件不存在。但是我已经检查了路径是正确的,甚至我把发色器放在usr/local/bin,app/文件夹中。
当我没有码头的时候它就能工作了。
我的代码:
...
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
....
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("headless");
chromeOptions.AddArgument("no-sandbox");
chromeOptions.PageLoadStrategy = PageLoadStrategy.Eager;
// var driver = new ChromeDriver(chromeOptions);
// var driver = new ChromeDriver("/usr/local/bin/",chromeOptions);
var driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, chromeOptions);错误:
An unhandled exception has occurred while executing the request.
System.ComponentModel.Win32Exception (2): No such file or directory
at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at OpenQA.Selenium.DriverService.Start()
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)我的文件
# install chromedriver
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
# Install Chrome WebDriver
RUN CHROMEDRIVER_VERSION=94.0.4606.61 && \
mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \
curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_mac64_m1.zip && \
unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \
rm /tmp/chromedriver_linux64.zip && \
chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver && \
ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver && \
chmod +x /usr/local/bin/chromedriver一揽子信息:
.Net 5
Selenium.WebDriver --version 4.0.1
ChromeDriver version 94.0.4606.41
Operating System: Ubuntu 20.发布于 2021-12-24 10:39:57
我使用的是远程驱动程序,而不是铬文件。
https://stackoverflow.com/questions/69907127
复制相似问题