@@ -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,22 +106,14 @@ 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
-
125
117
if ($StartURL ){
126
118
Enter-SeUrl - Driver $Driver - Url $StartURL
127
119
}
@@ -134,7 +126,7 @@ function Start-SeChrome {
134
126
function Start-SeInternetExplorer {
135
127
$InternetExplorer_Options = New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerOptions"
136
128
$InternetExplorer_Options.IgnoreZoomLevel = $true
137
- New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerDriver" - ArgumentList $InternetExplorer_Options
129
+ New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerDriver" - ArgumentList $InternetExplorer_Options
138
130
}
139
131
140
132
function Start-SeEdge {
@@ -169,7 +161,7 @@ function Start-SeFirefox {
169
161
}
170
162
171
163
function Stop-SeDriver {
172
- param ($Driver )
164
+ param ($Driver )
173
165
174
166
$Driver.Dispose ()
175
167
}
@@ -230,7 +222,7 @@ function Find-SeElement {
230
222
if ($PSCmdlet.ParameterSetName -eq " ById" ) {
231
223
$TargetElement = [OpenQA.Selenium.By ]::Id($Id )
232
224
}
233
-
225
+
234
226
if ($PSCmdlet.ParameterSetName -eq " ByLinkText" ) {
235
227
$TargetElement = [OpenQA.Selenium.By ]::LinkText($LinkText )
236
228
}
@@ -246,15 +238,15 @@ function Find-SeElement {
246
238
if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
247
239
$TargetElement = [OpenQA.Selenium.By ]::TagName($TagName )
248
240
}
249
-
241
+
250
242
if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
251
243
$TargetElement = [OpenQA.Selenium.By ]::XPath($XPath )
252
244
}
253
245
254
246
if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
255
247
$TargetElement = [OpenQA.Selenium.By ]::CssSelector($Css )
256
248
}
257
-
249
+
258
250
$WebDriverWait = New-Object - TypeName OpenQA.Selenium.Support.UI.WebDriverWait($Driver , (New-TimeSpan - Seconds $Timeout ))
259
251
$Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions ]::ElementExists($TargetElement )
260
252
$WebDriverWait.Until ($Condition )
@@ -287,7 +279,7 @@ function Find-SeElement {
287
279
if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
288
280
$Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
289
281
}
290
-
282
+
291
283
if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
292
284
$Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
293
285
}
@@ -315,17 +307,17 @@ function Invoke-SeClick {
315
307
}
316
308
317
309
function Get-SeKeys {
318
-
310
+
319
311
[OpenQA.Selenium.Keys ] | Get-Member - MemberType Property - Static | Select-Object - Property Name, @ {N = " ObjectString" ; E = { " [OpenQA.Selenium.Keys]::$ ( $_.Name ) " } }
320
312
}
321
313
322
314
function Send-SeKeys {
323
315
param ([OpenQA.Selenium.IWebElement ]$Element , [string ]$Keys )
324
-
316
+
325
317
foreach ($Key in @ (Get-SeKeys ).Name) {
326
318
$Keys = $Keys -replace " {{$Key }}" , [OpenQA.Selenium.Keys ]::$Key
327
319
}
328
-
320
+
329
321
$Element.SendKeys ($Keys )
330
322
}
331
323
@@ -352,7 +344,7 @@ function Remove-SeCookie {
352
344
353
345
function Set-SeCookie {
354
346
param (
355
- [ValidateNotNull ()]$Driver ,
347
+ [ValidateNotNull ()]$Driver ,
356
348
[string ]$Name ,
357
349
[string ]$Value ,
358
350
[string ]$Path ,
@@ -368,7 +360,7 @@ function Set-SeCookie {
368
360
Cookie(String, String, String, Nullable<DateTime>)
369
361
Initializes a new instance of the Cookie class with a specific name, value, path and expiration date.
370
362
Cookie(String, String, String, String, Nullable<DateTime>)
371
- Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date.
363
+ Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date.
372
364
#>
373
365
Begin {
374
366
if ($ExpiryDate -ne $null -and $ExpiryDate.GetType ().Name -ne ' DateTime' ){
@@ -420,7 +412,7 @@ function Get-SeElementAttribute {
420
412
421
413
Process {
422
414
$Element.GetAttribute ($Attribute )
423
- }
415
+ }
424
416
}
425
417
426
418
function Invoke-SeScreenshot {
@@ -456,7 +448,7 @@ function Get-SeWindow {
456
448
457
449
Process {
458
450
$Driver.WindowHandles
459
- }
451
+ }
460
452
}
461
453
462
454
function Switch-SeWindow {
@@ -467,5 +459,5 @@ function Switch-SeWindow {
467
459
468
460
Process {
469
461
$Driver.SwitchTo ().Window($Window )| Out-Null
470
- }
462
+ }
471
463
}
0 commit comments