@@ -6,12 +6,11 @@ function Start-SeChrome {
66 [array ]$Arguments ,
77 [switch ]$HideVersionHint
88 )
9- if ($Arguments ) {
9+ if ($Arguments ) {
1010 $Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
1111 $Chrome_Options.AddArguments ($Arguments )
1212 }
13- if (! $HideVersionHint )
14- {
13+ if (! $HideVersionHint ) {
1514 Write-Host " Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" - ForegroundColor Yellow
1615 }
1716 New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver" - ArgumentList $Chrome_Options
@@ -53,6 +52,8 @@ function Find-SeElement {
5352 $Driver ,
5453 [Parameter ()]
5554 $Element ,
55+ [Parameter (ParameterSetName = " ByCss" )]
56+ $Css ,
5657 [Parameter (ParameterSetName = " ByName" )]
5758 $Name ,
5859 [Parameter (ParameterSetName = " ById" )]
@@ -104,6 +105,9 @@ function Find-SeElement {
104105 if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
105106 $Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
106107 }
108+ if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
109+ $Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
110+ }
107111 }
108112}
109113
@@ -115,11 +119,12 @@ function Invoke-SeClick {
115119 [Switch ]$JavaScriptClick ,
116120 [Parameter ()]
117121 $Driver
118- )
122+ )
119123
120124 if ($JavaScriptClick ) {
121125 $Driver.ExecuteScript (" arguments[0].click()" , $Element )
122- } else {
126+ }
127+ else {
123128 $Element.Click ()
124129 }
125130
@@ -128,16 +133,16 @@ function Invoke-SeClick {
128133
129134function Get-SeKeys {
130135
131- [OpenQA.Selenium.Keys ] | Get-Member - MemberType Property - Static | Select-Object - Property Name, @ {N = " ObjectString" ; E = {" [OpenQA.Selenium.Keys]::$ ( $_.Name ) " } }
136+ [OpenQA.Selenium.Keys ] | Get-Member - MemberType Property - Static | Select-Object - Property Name, @ {N = " ObjectString" ; E = { " [OpenQA.Selenium.Keys]::$ ( $_.Name ) " } }
132137}
133138
134139function Send-SeKeys {
135140 param ([OpenQA.Selenium.IWebElement ]$Element , [string ]$Keys )
136141
137- foreach ($Key in @ (Get-SeKeys ).Name)
138- {
142+ foreach ($Key in @ (Get-SeKeys ).Name) {
139143 $Keys = $Keys -replace " {{$Key }}" , [OpenQA.Selenium.Keys ]::$Key
140144 }
145+
141146 $Element.SendKeys ($Keys )
142147}
143148
@@ -156,16 +161,16 @@ function Remove-SeCookie {
156161function Set-SeCookie {
157162 param ($Driver , $name , $value )
158163
159- $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
164+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
160165
161166 $Driver.Manage ().Cookies.AddCookie($cookie )
162167}
163168
164169function Get-SeElementAttribute {
165170 param (
166- [Parameter (ValueFromPipeline = $true , Mandatory = $true )]
171+ [Parameter (ValueFromPipeline = $true , Mandatory = $true )]
167172 [OpenQA.Selenium.IWebElement ]$Element ,
168- [Parameter (Mandatory = $true )]
173+ [Parameter (Mandatory = $true )]
169174 [string ]$Attribute
170175 )
171176
@@ -180,7 +185,8 @@ function Invoke-SeScreenshot {
180185 $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions ]::TakeScreenshot($Driver )
181186 if ($AsBase64EncodedString ) {
182187 $Screenshot.AsBase64EncodedString
183- } else {
188+ }
189+ else {
184190 $Screenshot
185191 }
186192}
@@ -194,9 +200,9 @@ function Save-SeScreenshot {
194200 [Parameter ()]
195201 [OpenQA.Selenium.ScreenshotImageFormat ]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat ]::Png)
196202
197- Process {
198- $Screenshot.SaveAsFile ($Path , $ImageFormat )
199- }
203+ Process {
204+ $Screenshot.SaveAsFile ($Path , $ImageFormat )
205+ }
200206}
201207
202208function Wait-SeElementExists {
@@ -206,16 +212,13 @@ function Wait-SeElementExists {
206212 $Id ,
207213 $Name
208214 )
209- if ($Id )
210- {
215+ if ($Id ) {
211216 $TargetElement = [OpenQA.Selenium.By ]::Id($Id )
212217 }
213- elseif ($Name )
214- {
218+ elseif ($Name ) {
215219 $TargetElement = [OpenQA.Selenium.By ]::Name($Name )
216220 }
217- else
218- {
221+ else {
219222 throw " Please specify -Id or -Name"
220223 }
221224 $WebDriverWait = New-Object OpenQA.Selenium.Support.UI.WebDriverWait $Driver , ($Timeout * 10000000 ) # ticks
0 commit comments