I'm attempting to create a PowerShell script to automate some testing tasks but falling at the first hurdle.
I have a folder with ChromeDriver 105.0.5195.52 (chromedriver.exe) and the Selenium Web Driver 4.4.0 for .NET (WebDriver.dll).
On the test server, .NET version 4.8.03761 and Google Chrome 105.0.5195.102 (64-Bit) are installed.
After executing the script, Chrome is briefly launched and then exits. I see the following message in the PowerShell window:
New-Object : Exception calling ".ctor" with "1" argument(s): "session not created
from tab crashed
(Session info: chrome=105.0.5195.102) (SessionNotCreated)"
In Task Manager, the ChromeDriver.exe continues to run. Subsequent runs yield the same
behaviour and message.
The script is:
$workingPath = 'C:\Users\Me\Desktop\LaunchTest'
if (($env:Path -split ';') -notcontains $workingPath) {
$env:Path += ";$workingPath"
}
$env:Path -split ';'
Add-Type -Path "$($workingPath)\WebDriver.dll"
$ChromeOptions = [OpenQA.Selenium.Chrome.ChromeOptions]::new()
$ChromeOptions.AddArguments('start-maximized')
$ChromeDriver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList #($ChromeOptions)
$ChromeDriver.Navigate().GoToURL('<https://google.co.uk>')
Any thoughts will be appreciated.
I faced quite similar problem.
My solution:
uninstall chrome 64-bit and remove its reminder
install chrome 32-bit instead
Related
I am able to successfully execute a Powershell script with Selenium 4.x although i need to run chrome under a user profile (which will persist). The objective is to save the cookies. For that I believe I will need to add options as defined in Saving chrome cookies Selenium. I do see something similar here although I need it for Powershell.
So how do I implement options that can be used by this command. (This command is primarily for selenium 4.x).
$browser = Start-SeDriver -Browser Chrome
This is all I could get, but I am unsure how to add it all up:
$ChromeOptions.addArguments("c:/users/PsUser");
With Module https://github.com/adamdriscoll/selenium-powershell v4:
$browser = Start-SeDriver -Browser Chrome -Arguments "--user-data-dir=C:\Users\$($env:username)\AppData\Local\Google\Chrome\User Data"
Without Module:
When you instantiate the ChromeDriver object you can pass a ChromeOptions argument.
So basically:
# Your working directory
$workingPath = 'C:\selenium'
# Add the working directory to the environment path.
# This is required for the ChromeDriver to work.
if (($env:Path -split ';') -notcontains $workingPath) {
$env:Path += ";$workingPath"
}
# OPTION 1: Import Selenium to PowerShell using the Add-Type cmdlet.
Add-Type -Path "$($workingPath)\WebDriver.dll"
# Create a new ChromeDriver Object instance.
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeOptions.AddArgument("--user-data-dir=C:\Users\$($env:username)\AppData\Local\Google\Chrome\User Data")
$chrome = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeOptions)
# Launch a browser and go to URL
$ChromeDriver.Navigate().GoToURL('https://google.com')
# Cleanup
$ChromeDriver.Close()
$ChromeDriver.Quit()
We've been using Selenium to automate some browser testing in Internet Explorer. On Windows 7 32-bit it works fine. However we're testing it on Windows 10 64-bit and it fails miserably.
Sometimes the browser doesn't even launch
If i change the driver versions, i can get the browser to launch but it hangs on the first page
The issue is only present when I use ForceCreateProcessApi. However I need to use ForceCreateProcessApi in order to use BrowserCommandLineArguments!
The exception is: The HTTP request to the remote WebDriver server for URL http://localhost:16639/session timed out after 60 seconds.
Here is the PowerShell code i use:
$seleniumOptions = New-Object OpenQA.Selenium.IE.InternetExplorerOptions
$seleniumOptions.InitialBrowserUrl = $SiteUrl
$seleniumOptions.ForceCreateProcessApi = $true
$seleniumOptions.BrowserCommandLineArguments = "-k"
$seleniumOptions.IgnoreZoomLevel = $true
New-Variable -Name IEDS -Value ([OpenQA.Selenium.IE.InternetExplorerDriverService]) -Force
$defaultservice = $IEDS::CreateDefaultService()
$seleniumDriver = New-Object OpenQA.Selenium.IE.InternetExplorerDriver -ArgumentList #($defaultservice, $seleniumOptions)
I've tried the following versions (x86 and x64 versions), and none of them work:
2.25.3
3.141
3.9.0
Can anybody advise on how to make this work? I've made sure that TabProcGrowth etc is set according to the documentation.
Thanks.
Try to use a 3.150.1 32-bit driver.
I'm not sure how it looks on PS - but I'm able to run IE with this driver config.
ie: { version: "3.150.1", arch: "ia32" }
Also I have a key for iexplore.exe here:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
from this config link
I am trying to install software using powershell silent scripting. To install this software we need to have JRE installed on machine. For this first we need to check weather JRE installed or not, if not installed then it needs to be installed. What approach needs to be followed?
I have tried with the below of code.
$LASTEXITCODE = 0
$workdir = "C:\Program Files (x86)\Java"
If (!(Test-Path $workdir))
{
$LASTEXITCODE = (Start-Process "D:\jre-6u26-windows-i586.exe" -ArgumentList "/s" -Wait -PassThru).Exitcode
}
If($LASTEXITCODE -eq 0)
{
$DCBdir = "C:\Program Files (x86)\Compart"
If (!(Test-Path $DCBdir))
{
$Installer="D:\sw.exe"
$responsefile="D:\Sresponse.varfile"
$a=#("-q", "-varfile", "$responsefile")
start-process $Installer -ArgumentList $a -wait
}
}
$chkdir = "C:\Program Files (x86)\SWFolder"
if(Test-Path -eq $chkdir)
{
[System.Windows.MessageBox]::Show('Installation completed successfully')
}
When I run script its workingfine as it is checking the previous installation and performing installation if not found the installation. But here I am getting as issue with this code.
If Java installed alredy means it should start the other installation. but here in my case its stopping the complete installation.
after installation completed, I need to display the message like " Installation completed". But here its not working. AnNy wrong in the above code..??
One package manager that I like to use is Chocolatey which has an approved package for JRE, it looks like. A quick check wmi will tell you whether or not java is installed:
$x = Get-WmiObject -Class Win32_Product -Filter "Name like 'Java(TM)%'" | Select -Expand Version
You could also use Test-Path pointed at registry keys you know exist for the package. Once you verify that JRE is not on the machine, then you can call out to Chocolatey to install it.
I'm trying to launch a build on a few Visual Studio 2005 solutions from a PowerShell Script and it returns this error:
MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location
of the component to the system path if it is installed elsewhere. [C:\path\to\solution\solutionToBuild.sln]
Done Building Project "C:\path\to\solution\solutionToBuild.sln" (default targets) -- FAILED.
Build FAILED.
"C:\path\to\solution\solutionToBuild.sln" (default target) (1) ->
(solutionToBuild target) ->
MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the locati
on of the component to the system path if it is installed elsewhere. [C:\path\to\solution\solutionToBuild.sln]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.84
I really have no idea why this message is returned since I have MSVS 2005 installed and I have .NET V2 installed:
PSChildName Version Release Product
----------- ------- ------- -------
v2.0.50727 2.0.50727.5420
v3.0 3.0.30729.5420
Windows Communication Foundation 3.0.4506.5420
Windows Presentation Foundation 3.0.6920.5011
v3.5 3.5.30729.5420
Client 4.6.01590 394806 4.6.2
Full 4.6.01590 394806 4.6.2
Client 4.0.0.0
It might be that I need to add something to my system environment path but the error message doesn't say what to add, so I'm a little bit at a loss here.
So I ended up changing the function I wrote completely and here's what I came up with (which worked for me):
function Build-MSVS2K5Solution {
param (
[parameter(mandatory=$true)][validateNotNullOrEmpty()][String] $solutionToBuild,
[parameter(mandatory=$true)][validateNotNullOrEmpty()][Array] $solutionEnv,
[parameter(mandatory=$false)][validateNotNullOrEmpty()][Switch] $autoOpenBuildLog = $false
)
process {
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Please wait while solutions are being rebuilt.",0,"Building Solution...",0x1)
cd "C:\"
if (Test-Path "C:\Windows\Microsoft.NET\Framework\v2.0.50727")
{
$msBuild = "C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe"
}
$buildArgs = $solutionToBuild + (Get-ChildItem $SolutionToBuild | Where { $_.Name -like "*.sln" }) +" /p:Configuration=Debug /p:Platform=Win32"
$buildLog = [Environment]::GetFolderPath("Desktop") + "\buildlog.log"
foreach ($solEnv in $solutionEnv ) {
$itemPath = "env:" + $solEnv.Substring(0, ($solEnv.ToString().LastIndexOf("=") ) )
$itemValue = $solEnv.Substring( ($solEnv.ToString().LastIndexOf("=")+1) )
Set-Item -Path $itemPath -Value $itemValue
}
Write-Output "Building $buildArgs..."
Start-Process -FilePath $msBuild -ArgumentList $buildArgs -RedirectStandardOutput $buildLog
if ($autoOpenBuildLog)
{
Write-Output "Getting content of : $buildLog"
Get-Content $buildLog -Tail 1 -Wait
}
}
}
$solutionEnv = "envName=envValue", "envName2=envValue2", "etc.=etc."
Build-MSVS2K5Solution -SolutionToBuild "C:\Path\to\solution\" -solutionEnv $solutionEnv -autoOpenBuildLog
It's not perfect, but it works. Basically, I send the path to the solution, the function finds the solution "*.sln" (I know the solution direrctory only contains one). It sets the environment variables received in a string, then starts the build and if $autoOpenBuildLog is called, the buildLog is printed in the powershell prompt.
Feel free to let me know if you have suggestions to improve the code!
Thank you #David Daugherty and #stijn !
I have created my own framework for Powershell scripts which I am using on a lot of 2008-servers without issues. Now was the time to try it out on the first 2012-server, but for some reason it fails.
I initially do some checking to ensure that paths are valid, then I try to load the logger
try {
$log = New-Logger -Configuration $log4NetFile -Dll $dll40Path
Write-Verbose "[Enable-Logger] Using 4.0 DLL"
} catch [System.Management.Automation.MethodInvocationException] {
Write-Verbose "[Enable-Logger] Using 3.5 instead of 4.0 DLL"
$log = New-Logger -Configuration $log4NetFile -Dll $dll35Path
} finally {
Write-Verbose "[Enable-Logger] Log is $log"
}
On all our 2008-servers it loads 4.0 without any issues, but on 2012 the $log-variable is always empty, meaning it cannot load the dll.
To ensure that it has nothing to do with the config file I did try the exact same code on 2008, and it worked.
Initial workaround
Did check Powershell-version
Powershell -Command "Write-Host $psversiontable.psversion"
which is 3.0 on the 2012-server. Starting the script with the 2.0 engine like this
Powershell -Version 2 -File alertXymon1-region3queues.ps1 -verbose
and it worked.
Final solution
Did some checking today and figured out that the problem was not caused by the DLL, but a code line that is loading the DLL
[void][Reflection.Assembly]::LoadFrom($log4netDllPath) | Out-Null
Found the post "Powershell 2.0 script not working in PS 3.0" which helped me out.
I have now tested the code without [void] on both Powershell 2.0 and 3.0 and it works like a charm