@@ -15,7 +15,8 @@ function Start-SeChrome {
1515 [switch ]$HideVersionHint ,
1616 [System.IO.FileInfo ]$DefaultDownloadPath ,
1717 [bool ]$DisableBuiltInPDFViewer = $true ,
18- [switch ]$Headless
18+ [switch ]$Headless ,
19+ [switch ]$Incognito
1920 )
2021
2122 $Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
@@ -33,6 +34,10 @@ function Start-SeChrome {
3334 $Chrome_Options.AddArguments (' headless' )
3435 }
3536
37+ if ($Incognito ) {
38+ $Chrome_Options.AddArguments (' Incognito' )
39+ }
40+
3641 if ($Arguments ) {
3742 $Chrome_Options.AddArguments ($Arguments )
3843 }
@@ -102,6 +107,8 @@ function Find-SeElement {
102107 $Driver ,
103108 [Parameter ()]
104109 $Element ,
110+ [Parameter ()][Switch ]$Wait ,
111+ [Parameter ()]$Timeout = 30 ,
105112 [Parameter (ParameterSetName = " ByCss" )]
106113 $Css ,
107114 [Parameter (ParameterSetName = " ByName" )]
@@ -136,36 +143,75 @@ function Find-SeElement {
136143 " Driver or element must be specified"
137144 }
138145
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 ))
146+ if ($Wait ){
147+ if ($PSCmdlet.ParameterSetName -eq " ByName" ) {
148+ $TargetElement = [OpenQA.Selenium.By ]::Name($Name )
149+ }
150+
151+ if ($PSCmdlet.ParameterSetName -eq " ById" ) {
152+ $TargetElement = [OpenQA.Selenium.By ]::Id($Id )
153+ }
154+
155+ if ($PSCmdlet.ParameterSetName -eq " ByLinkText" ) {
156+ $TargetElement = [OpenQA.Selenium.By ]::LinkText($LinkText )
157+ }
158+
159+ if ($PSCmdlet.ParameterSetName -eq " ByPartialLinkText" ) {
160+ $TargetElement = [OpenQA.Selenium.By ]::PartialLinkText($PartialLinkText )
161+ }
162+
163+ if ($PSCmdlet.ParameterSetName -eq " ByClassName" ) {
164+ $TargetElement = [OpenQA.Selenium.By ]::ClassName($ClassName )
165+ }
166+
167+ if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
168+ $TargetElement = [OpenQA.Selenium.By ]::TagName($TagName )
169+ }
170+
171+ if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
172+ $TargetElement = [OpenQA.Selenium.By ]::XPath($XPath )
173+ }
174+
175+ if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
176+ $TargetElement = [OpenQA.Selenium.By ]::CssSelector($Css )
177+ }
178+
179+ $WebDriverWait = New-Object - TypeName OpenQA.Selenium.Support.UI.WebDriverWait($Driver , (New-TimeSpan - Seconds $Timeout ))
180+ $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions ]::ElementExists($TargetElement )
181+ $WebDriverWait.Until ($Condition )
153182 }
154-
155- if ($PSCmdlet.ParameterSetName -eq " ByClassName" ) {
156- $Target.FindElements ([OpenQA.Selenium.By ]::ClassName($ClassName ))
157- }
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 ))
183+ else {
184+ if ($PSCmdlet.ParameterSetName -eq " ByName" ) {
185+ $Target.FindElements ([OpenQA.Selenium.By ]::Name($Name ))
186+ }
187+
188+ if ($PSCmdlet.ParameterSetName -eq " ById" ) {
189+ $Target.FindElements ([OpenQA.Selenium.By ]::Id($Id ))
190+ }
191+
192+ if ($PSCmdlet.ParameterSetName -eq " ByLinkText" ) {
193+ $Target.FindElements ([OpenQA.Selenium.By ]::LinkText($LinkText ))
194+ }
195+
196+ if ($PSCmdlet.ParameterSetName -eq " ByPartialLinkText" ) {
197+ $Target.FindElements ([OpenQA.Selenium.By ]::PartialLinkText($PartialLinkText ))
198+ }
199+
200+ if ($PSCmdlet.ParameterSetName -eq " ByClassName" ) {
201+ $Target.FindElements ([OpenQA.Selenium.By ]::ClassName($ClassName ))
202+ }
203+
204+ if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
205+ $Target.FindElements ([OpenQA.Selenium.By ]::TagName($TagName ))
206+ }
207+
208+ if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
209+ $Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
210+ }
211+
212+ if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
213+ $Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
214+ }
169215 }
170216 }
171217}
@@ -262,38 +308,3 @@ function Save-SeScreenshot {
262308 $Screenshot.SaveAsFile ($Path , $ImageFormat )
263309 }
264310}
265-
266- function Wait-SeElementExists {
267- param (
268- $Driver ,
269- $Timeout = 30 ,
270- $Id ,
271- $Name ,
272- $TagName ,
273- $ClassName
274- )
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-
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 )
297- }
298-
299-
0 commit comments