@@ -10,18 +10,21 @@ function Start-SeChrome {
10
10
)
11
11
12
12
$Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
13
+
13
14
if ($DefaultDownloadPath ){
14
15
Write-Host " Setting Default Download directory: $DefaultDownloadPath "
15
16
$Chrome_Options.AddUserProfilePreference (' download' , @ {' default_directory' = $ ($DefaultDownloadPath.FullName ); ' prompt_for_download' = $false ; })
16
17
}
18
+
17
19
if ($DisableBuiltInPDFViewer ){
18
20
$Chrome_Options.AddUserProfilePreference (' plugins' , @ {' always_open_pdf_externally' = $true ;})
19
21
}
20
- if ($Arguments ) {
22
+
23
+ if ($Arguments ) {
21
24
$Chrome_Options.AddArguments ($Arguments )
22
25
}
23
- if ( ! $HideVersionHint )
24
- {
26
+
27
+ if ( ! $HideVersionHint ) {
25
28
Write-Host " Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" - ForegroundColor Yellow
26
29
}
27
30
New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver" - ArgumentList $Chrome_Options
@@ -63,6 +66,8 @@ function Find-SeElement {
63
66
$Driver ,
64
67
[Parameter ()]
65
68
$Element ,
69
+ [Parameter (ParameterSetName = " ByCss" )]
70
+ $Css ,
66
71
[Parameter (ParameterSetName = " ByName" )]
67
72
$Name ,
68
73
[Parameter (ParameterSetName = " ById" )]
@@ -124,7 +129,7 @@ function Find-SeElement {
124
129
if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
125
130
$Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
126
131
}
127
-
132
+
128
133
if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
129
134
$Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
130
135
}
@@ -139,11 +144,12 @@ function Invoke-SeClick {
139
144
[Switch ]$JavaScriptClick ,
140
145
[Parameter ()]
141
146
$Driver
142
- )
147
+ )
143
148
144
149
if ($JavaScriptClick ) {
145
150
$Driver.ExecuteScript (" arguments[0].click()" , $Element )
146
- } else {
151
+ }
152
+ else {
147
153
$Element.Click ()
148
154
}
149
155
@@ -152,16 +158,16 @@ function Invoke-SeClick {
152
158
153
159
function Get-SeKeys {
154
160
155
- [OpenQA.Selenium.Keys ] | Get-Member - MemberType Property - Static | Select-Object - Property Name, @ {N = " ObjectString" ; E = {" [OpenQA.Selenium.Keys]::$ ( $_.Name ) " } }
161
+ [OpenQA.Selenium.Keys ] | Get-Member - MemberType Property - Static | Select-Object - Property Name, @ {N = " ObjectString" ; E = { " [OpenQA.Selenium.Keys]::$ ( $_.Name ) " } }
156
162
}
157
163
158
164
function Send-SeKeys {
159
165
param ([OpenQA.Selenium.IWebElement ]$Element , [string ]$Keys )
160
166
161
- foreach ($Key in @ (Get-SeKeys ).Name)
162
- {
167
+ foreach ($Key in @ (Get-SeKeys ).Name) {
163
168
$Keys = $Keys -replace " {{$Key }}" , [OpenQA.Selenium.Keys ]::$Key
164
169
}
170
+
165
171
$Element.SendKeys ($Keys )
166
172
}
167
173
@@ -180,16 +186,16 @@ function Remove-SeCookie {
180
186
function Set-SeCookie {
181
187
param ($Driver , $name , $value )
182
188
183
- $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
189
+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
184
190
185
191
$Driver.Manage ().Cookies.AddCookie($cookie )
186
192
}
187
193
188
194
function Get-SeElementAttribute {
189
195
param (
190
- [Parameter (ValueFromPipeline = $true , Mandatory = $true )]
196
+ [Parameter (ValueFromPipeline = $true , Mandatory = $true )]
191
197
[OpenQA.Selenium.IWebElement ]$Element ,
192
- [Parameter (Mandatory = $true )]
198
+ [Parameter (Mandatory = $true )]
193
199
[string ]$Attribute
194
200
)
195
201
@@ -204,7 +210,8 @@ function Invoke-SeScreenshot {
204
210
$Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions ]::TakeScreenshot($Driver )
205
211
if ($AsBase64EncodedString ) {
206
212
$Screenshot.AsBase64EncodedString
207
- } else {
213
+ }
214
+ else {
208
215
$Screenshot
209
216
}
210
217
}
@@ -218,9 +225,9 @@ function Save-SeScreenshot {
218
225
[Parameter ()]
219
226
[OpenQA.Selenium.ScreenshotImageFormat ]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat ]::Png)
220
227
221
- Process {
222
- $Screenshot.SaveAsFile ($Path , $ImageFormat )
223
- }
228
+ Process {
229
+ $Screenshot.SaveAsFile ($Path , $ImageFormat )
230
+ }
224
231
}
225
232
226
233
function Wait-SeElementExists {
@@ -232,12 +239,10 @@ function Wait-SeElementExists{
232
239
$TagName ,
233
240
$ClassName
234
241
)
235
- if ($Id )
236
- {
242
+ if ($Id ) {
237
243
$TargetElement = [OpenQA.Selenium.By ]::Id($Id )
238
244
}
239
- elseif ($Name )
240
- {
245
+ elseif ($Name ) {
241
246
$TargetElement = [OpenQA.Selenium.By ]::Name($Name )
242
247
}
243
248
elseif ($TagName )
0 commit comments