@@ -15,7 +15,9 @@ function Start-SeChrome {
15
15
[switch ]$HideVersionHint ,
16
16
[System.IO.FileInfo ]$DefaultDownloadPath ,
17
17
[bool ]$DisableBuiltInPDFViewer = $true ,
18
- [switch ]$Headless
18
+ [switch ]$Headless ,
19
+ [switch ]$Incognito ,
20
+ [switch ]$Maximized
19
21
)
20
22
21
23
$Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
@@ -33,6 +35,14 @@ function Start-SeChrome {
33
35
$Chrome_Options.AddArguments (' headless' )
34
36
}
35
37
38
+ if ($Incognito ) {
39
+ $Chrome_Options.AddArguments (' Incognito' )
40
+ }
41
+
42
+ if ($Maximized ) {
43
+ $Chrome_Options.AddArguments (' start-maximized' )
44
+ }
45
+
36
46
if ($Arguments ) {
37
47
$Chrome_Options.AddArguments ($Arguments )
38
48
}
@@ -50,7 +60,9 @@ function Start-SeChrome {
50
60
}
51
61
52
62
function Start-SeInternetExplorer {
53
- New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerDriver"
63
+ $InternetExplorer_Options = New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerOptions"
64
+ $InternetExplorer_Options.IgnoreZoomLevel = $true
65
+ New-Object - TypeName " OpenQA.Selenium.IE.InternetExplorerDriver" - ArgumentList $InternetExplorer_Options
54
66
}
55
67
56
68
function Start-SeEdge {
@@ -102,6 +114,8 @@ function Find-SeElement {
102
114
$Driver ,
103
115
[Parameter ()]
104
116
$Element ,
117
+ [Parameter ()][Switch ]$Wait ,
118
+ [Parameter ()]$Timeout = 30 ,
105
119
[Parameter (ParameterSetName = " ByCss" )]
106
120
$Css ,
107
121
[Parameter (ParameterSetName = " ByName" )]
@@ -136,36 +150,75 @@ function Find-SeElement {
136
150
" Driver or element must be specified"
137
151
}
138
152
139
- if ($PSCmdlet.ParameterSetName -eq " ByName" ) {
140
- $Target.FindElements ([OpenQA.Selenium.By ]::Name($Name ))
141
- }
142
-
143
- if ($PSCmdlet.ParameterSetName -eq " ById" ) {
144
- $Target.FindElements ([OpenQA.Selenium.By ]::Id($Id ))
145
- }
146
-
147
- if ($PSCmdlet.ParameterSetName -eq " ByLinkText" ) {
148
- $Target.FindElements ([OpenQA.Selenium.By ]::LinkText($LinkText ))
149
- }
150
-
151
- if ($PSCmdlet.ParameterSetName -eq " ByPartialLinkText" ) {
152
- $Target.FindElements ([OpenQA.Selenium.By ]::PartialLinkText($PartialLinkText ))
153
- }
154
-
155
- if ($PSCmdlet.ParameterSetName -eq " ByClassName" ) {
156
- $Target.FindElements ([OpenQA.Selenium.By ]::ClassName($ClassName ))
153
+ if ($Wait ){
154
+ if ($PSCmdlet.ParameterSetName -eq " ByName" ) {
155
+ $TargetElement = [OpenQA.Selenium.By ]::Name($Name )
156
+ }
157
+
158
+ if ($PSCmdlet.ParameterSetName -eq " ById" ) {
159
+ $TargetElement = [OpenQA.Selenium.By ]::Id($Id )
160
+ }
161
+
162
+ if ($PSCmdlet.ParameterSetName -eq " ByLinkText" ) {
163
+ $TargetElement = [OpenQA.Selenium.By ]::LinkText($LinkText )
164
+ }
165
+
166
+ if ($PSCmdlet.ParameterSetName -eq " ByPartialLinkText" ) {
167
+ $TargetElement = [OpenQA.Selenium.By ]::PartialLinkText($PartialLinkText )
168
+ }
169
+
170
+ if ($PSCmdlet.ParameterSetName -eq " ByClassName" ) {
171
+ $TargetElement = [OpenQA.Selenium.By ]::ClassName($ClassName )
172
+ }
173
+
174
+ if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
175
+ $TargetElement = [OpenQA.Selenium.By ]::TagName($TagName )
176
+ }
177
+
178
+ if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
179
+ $TargetElement = [OpenQA.Selenium.By ]::XPath($XPath )
180
+ }
181
+
182
+ if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
183
+ $TargetElement = [OpenQA.Selenium.By ]::CssSelector($Css )
184
+ }
185
+
186
+ $WebDriverWait = New-Object - TypeName OpenQA.Selenium.Support.UI.WebDriverWait($Driver , (New-TimeSpan - Seconds $Timeout ))
187
+ $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions ]::ElementExists($TargetElement )
188
+ $WebDriverWait.Until ($Condition )
157
189
}
158
-
159
- if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
160
- $Target.FindElements ([OpenQA.Selenium.By ]::TagName($TagName ))
161
- }
162
-
163
- if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
164
- $Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
165
- }
166
-
167
- if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
168
- $Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
190
+ else {
191
+ if ($PSCmdlet.ParameterSetName -eq " ByName" ) {
192
+ $Target.FindElements ([OpenQA.Selenium.By ]::Name($Name ))
193
+ }
194
+
195
+ if ($PSCmdlet.ParameterSetName -eq " ById" ) {
196
+ $Target.FindElements ([OpenQA.Selenium.By ]::Id($Id ))
197
+ }
198
+
199
+ if ($PSCmdlet.ParameterSetName -eq " ByLinkText" ) {
200
+ $Target.FindElements ([OpenQA.Selenium.By ]::LinkText($LinkText ))
201
+ }
202
+
203
+ if ($PSCmdlet.ParameterSetName -eq " ByPartialLinkText" ) {
204
+ $Target.FindElements ([OpenQA.Selenium.By ]::PartialLinkText($PartialLinkText ))
205
+ }
206
+
207
+ if ($PSCmdlet.ParameterSetName -eq " ByClassName" ) {
208
+ $Target.FindElements ([OpenQA.Selenium.By ]::ClassName($ClassName ))
209
+ }
210
+
211
+ if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
212
+ $Target.FindElements ([OpenQA.Selenium.By ]::TagName($TagName ))
213
+ }
214
+
215
+ if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
216
+ $Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
217
+ }
218
+
219
+ if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
220
+ $Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
221
+ }
169
222
}
170
223
}
171
224
}
@@ -217,10 +270,55 @@ function Remove-SeCookie {
217
270
}
218
271
219
272
function Set-SeCookie {
220
- param ($Driver , $name , $value )
273
+ param (
274
+ $Driver ,
275
+ [string ]$Name ,
276
+ [string ]$Value ,
277
+ [string ]$Path ,
278
+ [string ]$Domain ,
279
+ [datetime ]$ExpiryDate
280
+ )
281
+
282
+ <# Selenium Cookie Information
283
+ Cookie(String, String)
284
+ Initializes a new instance of the Cookie class with a specific name and value.
285
+ Cookie(String, String, String)
286
+ Initializes a new instance of the Cookie class with a specific name, value, and path.
287
+ Cookie(String, String, String, Nullable<DateTime>)
288
+ Initializes a new instance of the Cookie class with a specific name, value, path and expiration date.
289
+ Cookie(String, String, String, String, Nullable<DateTime>)
290
+ Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date.
291
+ #>
292
+
293
+ if ($Name -and $Value -and (! $Path -and ! $Domain -and ! $ExpiryDate )){
294
+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $Value
295
+ }
296
+ Elseif ($Name -and $Value -and $Path -and (! $Domain -and ! $ExpiryDate )){
297
+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $Value , $Path
298
+ }
299
+ Elseif ($Name -and $Value -and $Path -and $ExpiryDate -and ! $Domain ){
300
+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $Value , $Path , $ExpiryDate
301
+ }
302
+ Elseif ($Name -and $Value -and $Path -and $ExpiryDate -and $Domain ){
303
+ if ($Driver.Url -match $Domain ){
304
+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $Value , $Domain , $Path , $ExpiryDate
305
+ }
306
+ else {
307
+ Throw ' In order to set the cookie the browser needs to be on the cookie domain URL'
308
+ }
309
+ }
310
+ else {
311
+ Throw " Incorrect Cookie Layout:
312
+ Cookie(String, String)
313
+ Initializes a new instance of the Cookie class with a specific name and value.
314
+ Cookie(String, String, String)
315
+ Initializes a new instance of the Cookie class with a specific name, value, and path.
316
+ Cookie(String, String, String, Nullable<DateTime>)
317
+ Initializes a new instance of the Cookie class with a specific name, value, path and expiration date.
318
+ Cookie(String, String, String, String, Nullable<DateTime>)
319
+ Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date."
320
+ }
221
321
222
- $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
223
-
224
322
$Driver.Manage ().Cookies.AddCookie($cookie )
225
323
}
226
324
@@ -263,37 +361,23 @@ function Save-SeScreenshot {
263
361
}
264
362
}
265
363
266
- function Wait-SeElementExists {
364
+ function Get-SeWindow {
267
365
param (
268
- $Driver ,
269
- $Timeout = 30 ,
270
- $Id ,
271
- $Name ,
272
- $TagName ,
273
- $ClassName
366
+ [Parameter (Mandatory = $true )][OpenQA.Selenium.IWebDriver ]$Driver
274
367
)
275
- if ($Id ) {
276
- $TargetElement = [OpenQA.Selenium.By ]::Id($Id )
277
- }
278
- elseif ($Name ) {
279
- $TargetElement = [OpenQA.Selenium.By ]::Name($Name )
280
- }
281
- elseif ($TagName )
282
- {
283
- $TargetElement = [OpenQA.Selenium.By ]::TagName($TagName )
284
- }
285
- elseif ($ClassName )
286
- {
287
- $TargetElement = [OpenQA.Selenium.By ]::ClassName($ClassName )
288
- }
289
- else
290
- {
291
- throw " Please specify -Id or -Name or -TagName or -ClassName"
292
- }
293
368
294
- $WebDriverWait = New-Object - TypeName OpenQA.Selenium.Support.UI.WebDriverWait( $Driver , ( New-TimeSpan - Seconds $Timeout ))
295
- $Condition = [ OpenQA.Selenium.Support.UI.ExpectedConditions ]::ElementExists( $TargetElement )
296
- $WebDriverWait .Until ( $Condition )
369
+ Process {
370
+ $Driver .WindowHandles
371
+ }
297
372
}
298
373
374
+ function Switch-SeWindow {
375
+ param (
376
+ [Parameter (Mandatory = $true )][OpenQA.Selenium.IWebDriver ]$Driver ,
377
+ [Parameter (Mandatory = $true )]$Window
378
+ )
299
379
380
+ Process {
381
+ $Driver.SwitchTo ().Window($Window )| Out-Null
382
+ }
383
+ }
0 commit comments