.net 5 Selenium Web驱动程序在docker容器中不工作错误:没有这样的文件或目录



我在使用.net的selenium网络驱动程序时遇到问题,需要您的帮助。

我正在使用.net 5,并试图在Linux Docker容器上运行Selenium Web驱动程序;System.ComponentModel.Win32Exception没有这样的文件或目录"错误我以为chromedriver文件不存在。但我已经检查了路径是否正确,甚至我把chromeriver放在了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.

我使用的是远程驱动程序,而不是chrome文件。

相关内容

  • 没有找到相关文章

最新更新