@@ -8,7 +8,7 @@ elseif($IsMacOS){
8
8
$AssembliesPath = " $PSScriptRoot /assemblies/macos"
9
9
}
10
10
11
- # Grant Execution permission to assemblies on Linux and MacOS
11
+ # Grant Execution permission to assemblies on Linux and MacOS
12
12
if ($IsLinux -or $IsMacOS ){
13
13
# Check if powershell is NOT running as root
14
14
$AssemblieFiles = Get-ChildItem - Path $AssembliesPath | Where-Object {$_.Name -eq ' chromedriver' -or $_.Name -eq ' geckodriver' }
@@ -62,7 +62,7 @@ function Start-SeChrome {
62
62
}
63
63
PROCESS {
64
64
$Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
65
-
65
+
66
66
if ($DefaultDownloadPath ){
67
67
Write-Verbose " Setting Default Download directory: $DefaultDownloadPath "
68
68
$Chrome_Options.AddUserProfilePreference (' download' , @ {' default_directory' = $ ($DefaultDownloadPath.FullName ); ' prompt_for_download' = $false ; })
@@ -71,11 +71,11 @@ function Start-SeChrome {
71
71
Write-Verbose " Setting Profile directory: $ProfileDirectoryPath "
72
72
$Chrome_Options.AddArgument (" user-data-dir=$ProfileDirectoryPath " )
73
73
}
74
-
74
+
75
75
if ($DisableBuiltInPDFViewer ){
76
76
$Chrome_Options.AddUserProfilePreference (' plugins' , @ {' always_open_pdf_externally' = $true ;})
77
77
}
78
-
78
+
79
79
if ($Headless ) {
80
80
$Chrome_Options.AddArguments (' headless' )
81
81
}
@@ -97,7 +97,7 @@ function Start-SeChrome {
97
97
$Chrome_Options.AddArguments ($Argument )
98
98
}
99
99
}
100
-
100
+
101
101
if (! $HideVersionHint ) {
102
102
Write-Verbose " Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'"
103
103
}
@@ -106,14 +106,22 @@ function Start-SeChrome {
106
106
$Driver = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver" - ArgumentList $AssembliesPath , $Chrome_Options
107
107
}
108
108
else {
109
- $Driver = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver" - ArgumentList $Chrome_Options
109
+ $Driver = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver" - ArgumentList $Chrome_Options
110
110
}
111
111
112
112
if ($Minimized ){
113
113
$driver.Manage ().Window.Minimize();
114
114
115
115
}
116
116
117
+ if ($Headless -and $DefaultDownloadPath ) {
118
+ $CmdParams = New-Object ' system.collections.generic.dictionary[[System.String],[System.Object]]]'
119
+ $CmdParams.Add (' behavior' , ' allow' )
120
+ $CmdParams.Add (' downloadPath' , $DefaultDownloadPath.FullName )
121
+
122
+ $Driver.ExecuteChromeCommand (' Page.setDownloadBehavior' , $CmdParams )
123
+ }
124
+
117
125
if ($StartURL ){
118
126
Enter-SeUrl - Driver $Driver - Url $StartURL
119
127
}
@@ -126,7 +134,7 @@ function Start-SeChrome {
126
134
function Start-SeInternetExplorer {
127
135
$InternetExplorer_Options = New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerOptions"
128
136
$InternetExplorer_Options.IgnoreZoomLevel = $true
129
- New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerDriver" - ArgumentList $InternetExplorer_Options
137
+ New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerDriver" - ArgumentList $InternetExplorer_Options
130
138
}
131
139
132
140
function Start-SeEdge {
@@ -161,7 +169,7 @@ function Start-SeFirefox {
161
169
}
162
170
163
171
function Stop-SeDriver {
164
- param ($Driver )
172
+ param ($Driver )
165
173
166
174
$Driver.Dispose ()
167
175
}
@@ -222,7 +230,7 @@ function Find-SeElement {
222
230
if ($PSCmdlet.ParameterSetName -eq " ById" ) {
223
231
$TargetElement = [OpenQA.Selenium.By ]::Id($Id )
224
232
}
225
-
233
+
226
234
if ($PSCmdlet.ParameterSetName -eq " ByLinkText" ) {
227
235
$TargetElement = [OpenQA.Selenium.By ]::LinkText($LinkText )
228
236
}
@@ -238,15 +246,15 @@ function Find-SeElement {
238
246
if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
239
247
$TargetElement = [OpenQA.Selenium.By ]::TagName($TagName )
240
248
}
241
-
249
+
242
250
if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
243
251
$TargetElement = [OpenQA.Selenium.By ]::XPath($XPath )
244
252
}
245
253
246
254
if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
247
255
$TargetElement = [OpenQA.Selenium.By ]::CssSelector($Css )
248
256
}
249
-
257
+
250
258
$WebDriverWait = New-Object - TypeName OpenQA.Selenium.Support.UI.WebDriverWait($Driver , (New-TimeSpan - Seconds $Timeout ))
251
259
$Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions ]::ElementExists($TargetElement )
252
260
$WebDriverWait.Until ($Condition )
@@ -279,7 +287,7 @@ function Find-SeElement {
279
287
if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
280
288
$Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
281
289
}
282
-
290
+
283
291
if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
284
292
$Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
285
293
}
@@ -307,17 +315,17 @@ function Invoke-SeClick {
307
315
}
308
316
309
317
function Get-SeKeys {
310
-
318
+
311
319
[OpenQA.Selenium.Keys ] | Get-Member - MemberType Property - Static | Select-Object - Property Name, @ {N = " ObjectString" ; E = { " [OpenQA.Selenium.Keys]::$ ( $_.Name ) " } }
312
320
}
313
321
314
322
function Send-SeKeys {
315
323
param ([OpenQA.Selenium.IWebElement ]$Element , [string ]$Keys )
316
-
324
+
317
325
foreach ($Key in @ (Get-SeKeys ).Name) {
318
326
$Keys = $Keys -replace " {{$Key }}" , [OpenQA.Selenium.Keys ]::$Key
319
327
}
320
-
328
+
321
329
$Element.SendKeys ($Keys )
322
330
}
323
331
@@ -344,7 +352,7 @@ function Remove-SeCookie {
344
352
345
353
function Set-SeCookie {
346
354
param (
347
- [ValidateNotNull ()]$Driver ,
355
+ [ValidateNotNull ()]$Driver ,
348
356
[string ]$Name ,
349
357
[string ]$Value ,
350
358
[string ]$Path ,
@@ -360,7 +368,7 @@ function Set-SeCookie {
360
368
Cookie(String, String, String, Nullable<DateTime>)
361
369
Initializes a new instance of the Cookie class with a specific name, value, path and expiration date.
362
370
Cookie(String, String, String, String, Nullable<DateTime>)
363
- Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date.
371
+ Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date.
364
372
#>
365
373
Begin {
366
374
if ($ExpiryDate -ne $null -and $ExpiryDate.GetType ().Name -ne ' DateTime' ){
@@ -412,7 +420,7 @@ function Get-SeElementAttribute {
412
420
413
421
Process {
414
422
$Element.GetAttribute ($Attribute )
415
- }
423
+ }
416
424
}
417
425
418
426
function Invoke-SeScreenshot {
@@ -448,7 +456,7 @@ function Get-SeWindow {
448
456
449
457
Process {
450
458
$Driver.WindowHandles
451
- }
459
+ }
452
460
}
453
461
454
462
function Switch-SeWindow {
@@ -459,5 +467,5 @@ function Switch-SeWindow {
459
467
460
468
Process {
461
469
$Driver.SwitchTo ().Window($Window )| Out-Null
462
- }
470
+ }
463
471
}
0 commit comments