@@ -15,7 +15,9 @@ function Start-SeChrome {
1515 [switch ]$HideVersionHint ,
1616 [System.IO.FileInfo ]$DefaultDownloadPath ,
1717 [bool ]$DisableBuiltInPDFViewer = $true ,
18- [switch ]$Headless
18+ [switch ]$Headless ,
19+ [switch ]$Incognito ,
20+ [switch ]$Maximized
1921 )
2022
2123 $Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
@@ -33,6 +35,14 @@ function Start-SeChrome {
3335 $Chrome_Options.AddArguments (' headless' )
3436 }
3537
38+ if ($Incognito ) {
39+ $Chrome_Options.AddArguments (' Incognito' )
40+ }
41+
42+ if ($Maximized ) {
43+ $Chrome_Options.AddArguments (' start-maximized' )
44+ }
45+
3646 if ($Arguments ) {
3747 $Chrome_Options.AddArguments ($Arguments )
3848 }
@@ -50,7 +60,9 @@ function Start-SeChrome {
5060}
5161
5262function 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
5466}
5567
5668function Start-SeEdge {
@@ -102,6 +114,8 @@ function Find-SeElement {
102114 $Driver ,
103115 [Parameter ()]
104116 $Element ,
117+ [Parameter ()][Switch ]$Wait ,
118+ [Parameter ()]$Timeout = 30 ,
105119 [Parameter (ParameterSetName = " ByCss" )]
106120 $Css ,
107121 [Parameter (ParameterSetName = " ByName" )]
@@ -136,36 +150,75 @@ function Find-SeElement {
136150 " Driver or element must be specified"
137151 }
138152
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 )
157189 }
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+ }
169222 }
170223 }
171224}
@@ -217,10 +270,55 @@ function Remove-SeCookie {
217270}
218271
219272function 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+ }
221321
222- $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
223-
224322 $Driver.Manage ().Cookies.AddCookie($cookie )
225323}
226324
@@ -263,37 +361,23 @@ function Save-SeScreenshot {
263361 }
264362}
265363
266- function Wait-SeElementExists {
364+ function Get-SeWindow {
267365 param (
268- $Driver ,
269- $Timeout = 30 ,
270- $Id ,
271- $Name ,
272- $TagName ,
273- $ClassName
366+ [Parameter (Mandatory = $true )][OpenQA.Selenium.IWebDriver ]$Driver
274367 )
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- }
293368
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+ }
297372}
298373
374+ function Switch-SeWindow {
375+ param (
376+ [Parameter (Mandatory = $true )][OpenQA.Selenium.IWebDriver ]$Driver ,
377+ [Parameter (Mandatory = $true )]$Window
378+ )
299379
380+ Process {
381+ $Driver.SwitchTo ().Window($Window )| Out-Null
382+ }
383+ }
0 commit comments