I am using Selenium to get info from a webpage and when I run the script with powershell 7.2.1 and as the user I am using in powershell universal it runs fine. But in automation I get some wild errors.
$selRelativePath = "E:\PowerShellUniversal\UniversalAutomation\Repository\SeleniumTest\include"
#needed for selenium and edgedriver to be in the environment path.
$workingPath = (Get-Item -Path $selRelativePath).fullname
if (($env:Path -split ';') -notcontains $workingPath) {
$env:Path += ";$workingPath"
}
Add-Type -Path "$($workingPath)\WebDriver.dll"
$edgeOptions = New-Object OpenQA.Selenium.Edge.EdgeOptions
$edgeOptions.AddArgument("--headless")
$EdgeDriver = New-Object OpenQA.Selenium.Edge.EdgeDriver($edgeOptions)
$EdgeDriver.Navigate().GoToUrl("https://www.ipchicken.com")
$pageData = $EdgeDriver.FindElement([OpenQA.Selenium.By]::TagName("body")).Text
$EdgeDriver.Quit()
Write-Output $pageData
Just for some simple setup you will need the Selenium DLL and Edge Driver
This above runs outside of automation but not in it.
This is what I am seeing.
Mar 15, 2022 2:19 PM [error] Exception calling ".ctor" with "2" argument(s): "Cannot start the driver service on http://localhost:62359/"
Mar 15, 2022 2:19 PM [error] You cannot call a method on a null-valued expression.
Mar 15, 2022 2:19 PM [error] You cannot call a method on a null-valued expression.
Mar 15, 2022 2:19 PM [error] You cannot call a method on a null-valued expression.
Can you try enabling the interact with desktop option for the PSU service (if you haven’t already). It might have a hard time running a browser without that.
That made no difference but since it was running as local system I figured that might be a problem. So I change PSU to run under a service account and that solved it. I probably should have done that a while ago but that seems to be the ticket.