I have a simple script that tries to login to a website with Selenium for C# like this:
IWebDriver WebDriver = new ChromeDriver();
WebDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
WebDriver.Navigate().GoToUrl("https://mysite.de/");
// Login
var tenantTextbox = WebDriver.FindElement(By.Id("tenantTextbox"));
var userTextTextbox = WebDriver.FindElement(By.Id("userTextTextbox"));
var passwordTextbox = WebDriver.FindElement(By.Id("passwordTextbox"));
var loginButton = WebDriver.FindElement(By.ClassName("loginbutton"));
tenantTextbox.SendKeys("Tenant");
userTextTextbox.SendKeys("sysadmin");
passwordTextbox.SendKeys("password");
loginButton.Click();
There is no issue on Windows, but when running it in Linux, it fails with some errors.
dotnet restore -r linux-x64
and dotnet publish --configuration Release -r linux-x64 --no-self-contained --no-restore --output publish/
. If I try to run dotnet --roll-forward Major /srv/publish/UiTester.dll
(Roll forward is used because the app is on Net7.0 still, but Net8.0 is installed on the server), the following error occurs:Unhandled exception. OpenQA.Selenium.NoSuchDriverException: Unable to obtain chrome using Selenium Manager; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
---> OpenQA.Selenium.WebDriverException: Error starting process: /srv/publish/selenium-manager/linux/selenium-manager --browser "chrome" --output json
---> System.ComponentModel.Win32Exception (13): An error occurred trying to start process '/srv/publish/selenium-manager/linux/selenium-manager' with working directory '/srv'. Permission denied
chmod +x /srv/publish/selenium-manager/linux/selenium-manager
, the issue is gone, but the following error occurs:Unhandled exception. System.InvalidOperationException: session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)
(The process started from chrome location /root/.cache/selenium/chrome/linux64/120.0.6099.109/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) (SessionNotCreated)
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String 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(ChromeOptions options)
--headless
--remote-debugging-port=60000
--no-sandbox
--disable-dev-shm-usage
I tried setting all of them in various combinations, nothing changed the behaviour (Except if --remote-debugging-port=60000
was set --> This lead to an error where Chrome told me that the dev port cannot be set somehow).
Does anyone have some additional ideas what I can check?
Version information:
Don't judge me, this is horrible stupid in my case...
I just needed to install the correct version of Chrome like this to fix the issue:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
And if that fails with unmet dependecies, just install them manually or with sudo apt -f install
.
P.S. I also had to set the --headless
and --no-sandbox
options like this:
var options = new ChromeOptions();
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
WebDriver = new ChromeDriver(options);