I am running a Docker-based PowerShell Universal (PSU) environment on a Linux image and trying to automate tasks using the Selenium module. Despite successfully installing the module, I am facing several issues when creating Selenium objects such as ChromeOptions
or starting browsers like Chrome and Firefox.
Environment Details:
- OS: Linux (Docker container)
- PowerShell Version: 7.3.9
- Selenium Module Version: 3.0.1 (Installed from PSGallery)
What I Did:
-
Installed Selenium Module:
Install-Module -Name Selenium -Force Import-Module Selenium Get-InstalledModule -Name Selenium
Result: Successfully installed and imported the module.
-
Verified WebDriver Binaries:
which chromedriver which google-chrome which firefox which geckodriver
Result: All binaries are located in
/usr/bin/
and are executable. -
Set Up Xvfb (Headless Server):
Xvfb :99 -screen 0 1920x1080x24 & export DISPLAY=:99
Error:
Fatal server error: Server is already active for display 99.
Fix Attempt: Removed the lock file and retried:
rm -f /tmp/.X99-lock Xvfb :99 -screen 0 1920x1080x24 & export DISPLAY=:99
Result: Process started without errors after removing the lock file.
-
Attempted to Create Chrome Options in PowerShell:
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions $ChromeOptions.AddArgument("--headless") $ChromeOptions.AddArgument("--no-sandbox") $ChromeOptions.AddArgument("--disable-dev-shm-usage") $ChromeOptions.AddArgument("--disable-gpu")
Error:
New-Object: Cannot find type [OpenQA.Selenium.Chrome.ChromeOptions]: verify that the assembly containing this type is loaded.
-
Attempted to Start Chrome in Headless Mode:
$Driver = Start-SeChrome -ChromeOptions $ChromeOptions
Error:
Start-SeChrome: A parameter cannot be found that matches parameter name 'ChromeOptions'.
-
Tried Manually Loading DLLs:
Add-Type -Path "/root/Selenium/Selenium/WebDriver.dll" Add-Type -Path "/root/Selenium/Selenium/WebDriver.Support.dll"
Error:
Add-Type: Cannot bind parameter 'Path' to the target. Exception setting 'Path': Cannot find path...
-
Checked Selenium Module Path:
$Module = Get-Module Selenium $ModulePath = $Module.ModuleBase
Result: Selenium module path is correctly retrieved.
-
Tried Launching Firefox:
$FirefoxOptions = New-Object OpenQA.Selenium.Firefox.FirefoxOptions $FirefoxOptions.BrowserExecutableLocation = "/usr/bin/firefox" $Driver = Start-SeFirefox -FirefoxOptions $FirefoxOptions
Error:
New-Object: Cannot find type [OpenQA.Selenium.Firefox.FirefoxOptions]: verify that the assembly containing this type is loaded.
Summary of Errors Encountered:
Cannot find type [OpenQA.Selenium.Chrome.ChromeOptions]
in PowerShell.Start-SeChrome: A parameter cannot be found that matches parameter name 'ChromeOptions'.
Cannot find path '/root/Selenium/Selenium/WebDriver.dll'
when manually loading DLLs.- Issues with running
Xvfb
due to an active display server lock.
Can someone help me fix this issue ?