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:
<code>Install-Module -Name Selenium -ForceImport-Module SeleniumGet-InstalledModule -Name Selenium</code><code>Install-Module -Name Selenium -Force Import-Module Selenium Get-InstalledModule -Name Selenium </code>Install-Module -Name Selenium -Force Import-Module Selenium Get-InstalledModule -Name Selenium
Result: Successfully installed and imported the module.
-
Verified WebDriver Binaries:
<code>which chromedriverwhich google-chromewhich firefoxwhich geckodriver</code><code>which chromedriver which google-chrome which firefox which geckodriver </code>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):
<code>Xvfb :99 -screen 0 1920x1080x24 &export DISPLAY=:99</code><code>Xvfb :99 -screen 0 1920x1080x24 & export DISPLAY=:99 </code>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:
<code>rm -f /tmp/.X99-lockXvfb :99 -screen 0 1920x1080x24 &export DISPLAY=:99</code><code>rm -f /tmp/.X99-lock Xvfb :99 -screen 0 1920x1080x24 & export DISPLAY=:99 </code>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:
<code>$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions$ChromeOptions.AddArgument("--headless")$ChromeOptions.AddArgument("--no-sandbox")$ChromeOptions.AddArgument("--disable-dev-shm-usage")$ChromeOptions.AddArgument("--disable-gpu")</code><code>$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions $ChromeOptions.AddArgument("--headless") $ChromeOptions.AddArgument("--no-sandbox") $ChromeOptions.AddArgument("--disable-dev-shm-usage") $ChromeOptions.AddArgument("--disable-gpu") </code>$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:
<code>$Driver = Start-SeChrome -ChromeOptions $ChromeOptions</code><code>$Driver = Start-SeChrome -ChromeOptions $ChromeOptions </code>$Driver = Start-SeChrome -ChromeOptions $ChromeOptions
Error:
Start-SeChrome: A parameter cannot be found that matches parameter name 'ChromeOptions'.
-
Tried Manually Loading DLLs:
<code>Add-Type -Path "/root/Selenium/Selenium/WebDriver.dll"Add-Type -Path "/root/Selenium/Selenium/WebDriver.Support.dll"</code><code>Add-Type -Path "/root/Selenium/Selenium/WebDriver.dll" Add-Type -Path "/root/Selenium/Selenium/WebDriver.Support.dll" </code>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:
<code>$Module = Get-Module Selenium$ModulePath = $Module.ModuleBase</code><code>$Module = Get-Module Selenium $ModulePath = $Module.ModuleBase </code>$Module = Get-Module Selenium $ModulePath = $Module.ModuleBase
Result: Selenium module path is correctly retrieved.
-
Tried Launching Firefox:
<code>$FirefoxOptions = New-Object OpenQA.Selenium.Firefox.FirefoxOptions$FirefoxOptions.BrowserExecutableLocation = "/usr/bin/firefox"$Driver = Start-SeFirefox -FirefoxOptions $FirefoxOptions</code><code>$FirefoxOptions = New-Object OpenQA.Selenium.Firefox.FirefoxOptions $FirefoxOptions.BrowserExecutableLocation = "/usr/bin/firefox" $Driver = Start-SeFirefox -FirefoxOptions $FirefoxOptions </code>$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 ?