@@ -6,12 +6,11 @@ function Start-SeChrome {
6
6
[array ]$Arguments ,
7
7
[switch ]$HideVersionHint
8
8
)
9
- if ($Arguments ) {
9
+ if ($Arguments ) {
10
10
$Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
11
11
$Chrome_Options.AddArguments ($Arguments )
12
12
}
13
- if (! $HideVersionHint )
14
- {
13
+ if (! $HideVersionHint ) {
15
14
Write-Host " Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" - ForegroundColor Yellow
16
15
}
17
16
New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver" - ArgumentList $Chrome_Options
@@ -53,6 +52,8 @@ function Find-SeElement {
53
52
$Driver ,
54
53
[Parameter ()]
55
54
$Element ,
55
+ [Parameter (ParameterSetName = " ByCss" )]
56
+ $Css ,
56
57
[Parameter (ParameterSetName = " ByName" )]
57
58
$Name ,
58
59
[Parameter (ParameterSetName = " ById" )]
@@ -104,6 +105,9 @@ function Find-SeElement {
104
105
if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
105
106
$Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
106
107
}
108
+ if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
109
+ $Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
110
+ }
107
111
}
108
112
}
109
113
@@ -115,11 +119,12 @@ function Invoke-SeClick {
115
119
[Switch ]$JavaScriptClick ,
116
120
[Parameter ()]
117
121
$Driver
118
- )
122
+ )
119
123
120
124
if ($JavaScriptClick ) {
121
125
$Driver.ExecuteScript (" arguments[0].click()" , $Element )
122
- } else {
126
+ }
127
+ else {
123
128
$Element.Click ()
124
129
}
125
130
@@ -128,16 +133,16 @@ function Invoke-SeClick {
128
133
129
134
function Get-SeKeys {
130
135
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 ) " } }
132
137
}
133
138
134
139
function Send-SeKeys {
135
140
param ([OpenQA.Selenium.IWebElement ]$Element , [string ]$Keys )
136
141
137
- foreach ($Key in @ (Get-SeKeys ).Name)
138
- {
142
+ foreach ($Key in @ (Get-SeKeys ).Name) {
139
143
$Keys = $Keys -replace " {{$Key }}" , [OpenQA.Selenium.Keys ]::$Key
140
144
}
145
+
141
146
$Element.SendKeys ($Keys )
142
147
}
143
148
@@ -156,16 +161,16 @@ function Remove-SeCookie {
156
161
function Set-SeCookie {
157
162
param ($Driver , $name , $value )
158
163
159
- $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
164
+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
160
165
161
166
$Driver.Manage ().Cookies.AddCookie($cookie )
162
167
}
163
168
164
169
function Get-SeElementAttribute {
165
170
param (
166
- [Parameter (ValueFromPipeline = $true , Mandatory = $true )]
171
+ [Parameter (ValueFromPipeline = $true , Mandatory = $true )]
167
172
[OpenQA.Selenium.IWebElement ]$Element ,
168
- [Parameter (Mandatory = $true )]
173
+ [Parameter (Mandatory = $true )]
169
174
[string ]$Attribute
170
175
)
171
176
@@ -180,7 +185,8 @@ function Invoke-SeScreenshot {
180
185
$Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions ]::TakeScreenshot($Driver )
181
186
if ($AsBase64EncodedString ) {
182
187
$Screenshot.AsBase64EncodedString
183
- } else {
188
+ }
189
+ else {
184
190
$Screenshot
185
191
}
186
192
}
@@ -194,9 +200,9 @@ function Save-SeScreenshot {
194
200
[Parameter ()]
195
201
[OpenQA.Selenium.ScreenshotImageFormat ]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat ]::Png)
196
202
197
- Process {
198
- $Screenshot.SaveAsFile ($Path , $ImageFormat )
199
- }
203
+ Process {
204
+ $Screenshot.SaveAsFile ($Path , $ImageFormat )
205
+ }
200
206
}
201
207
202
208
function Wait-SeElementExists {
@@ -206,16 +212,13 @@ function Wait-SeElementExists {
206
212
$Id ,
207
213
$Name
208
214
)
209
- if ($Id )
210
- {
215
+ if ($Id ) {
211
216
$TargetElement = [OpenQA.Selenium.By ]::Id($Id )
212
217
}
213
- elseif ($Name )
214
- {
218
+ elseif ($Name ) {
215
219
$TargetElement = [OpenQA.Selenium.By ]::Name($Name )
216
220
}
217
- else
218
- {
221
+ else {
219
222
throw " Please specify -Id or -Name"
220
223
}
221
224
$WebDriverWait = New-Object OpenQA.Selenium.Support.UI.WebDriverWait $Driver , ($Timeout * 10000000 ) # ticks
0 commit comments