@@ -4,12 +4,26 @@ function Start-SeChrome {
4
4
Param (
5
5
[Parameter (Mandatory = $false )]
6
6
[array ]$Arguments ,
7
- [switch ]$HideVersionHint
7
+ [switch ]$HideVersionHint ,
8
+ [System.IO.FileInfo ]$DefaultDownloadPath ,
9
+ [bool ]$DisableBuiltInPDFViewer = $true
8
10
)
11
+
12
+ $Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
13
+
14
+ if ($DefaultDownloadPath ){
15
+ Write-Host " Setting Default Download directory: $DefaultDownloadPath "
16
+ $Chrome_Options.AddUserProfilePreference (' download' , @ {' default_directory' = $ ($DefaultDownloadPath.FullName ); ' prompt_for_download' = $false ; })
17
+ }
18
+
19
+ if ($DisableBuiltInPDFViewer ){
20
+ $Chrome_Options.AddUserProfilePreference (' plugins' , @ {' always_open_pdf_externally' = $true ;})
21
+ }
22
+
9
23
if ($Arguments ) {
10
- $Chrome_Options = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeOptions"
11
24
$Chrome_Options.AddArguments ($Arguments )
12
25
}
26
+
13
27
if (! $HideVersionHint ) {
14
28
Write-Host " Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" - ForegroundColor Yellow
15
29
}
@@ -62,10 +76,16 @@ function Find-SeElement {
62
76
$ClassName ,
63
77
[Parameter (ParameterSetName = " ByLinkText" )]
64
78
$LinkText ,
79
+ [Parameter (ParameterSetName = " ByPartialLinkText" )]
80
+ $PartialLinkText ,
65
81
[Parameter (ParameterSetName = " ByTagName" )]
66
82
$TagName ,
67
83
[Parameter (ParameterSetName = " ByXPath" )]
68
- $XPath )
84
+ $XPath ,
85
+ [Parameter (ParameterSetName = " ByCss" )]
86
+ $Css
87
+ )
88
+
69
89
70
90
Process {
71
91
@@ -94,6 +114,10 @@ function Find-SeElement {
94
114
$Target.FindElements ([OpenQA.Selenium.By ]::LinkText($LinkText ))
95
115
}
96
116
117
+ if ($PSCmdlet.ParameterSetName -eq " ByPartialLinkText" ) {
118
+ $Target.FindElements ([OpenQA.Selenium.By ]::PartialLinkText($PartialLinkText ))
119
+ }
120
+
97
121
if ($PSCmdlet.ParameterSetName -eq " ByClassName" ) {
98
122
$Target.FindElements ([OpenQA.Selenium.By ]::ClassName($ClassName ))
99
123
}
@@ -105,6 +129,7 @@ function Find-SeElement {
105
129
if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
106
130
$Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
107
131
}
132
+
108
133
if ($PSCmdlet.ParameterSetName -eq " ByCss" ) {
109
134
$Target.FindElements ([OpenQA.Selenium.By ]::CssSelector($Css ))
110
135
}
@@ -205,23 +230,35 @@ function Save-SeScreenshot {
205
230
}
206
231
}
207
232
208
- function Wait-SeElementExists {
233
+ function Wait-SeElementExists {
209
234
param (
210
235
$Driver ,
211
236
$Timeout = 30 ,
212
237
$Id ,
213
- $Name
238
+ $Name ,
239
+ $TagName ,
240
+ $ClassName
214
241
)
215
242
if ($Id ) {
216
243
$TargetElement = [OpenQA.Selenium.By ]::Id($Id )
217
244
}
218
245
elseif ($Name ) {
219
246
$TargetElement = [OpenQA.Selenium.By ]::Name($Name )
220
247
}
221
- else {
222
- throw " Please specify -Id or -Name"
248
+ elseif ($TagName )
249
+ {
250
+ $TargetElement = [OpenQA.Selenium.By ]::TagName($TagName )
251
+ }
252
+ elseif ($ClassName )
253
+ {
254
+ $TargetElement = [OpenQA.Selenium.By ]::ClassName($ClassName )
223
255
}
224
- $WebDriverWait = New-Object OpenQA.Selenium.Support.UI.WebDriverWait $Driver , ($Timeout * 10000000 ) # ticks
256
+ else
257
+ {
258
+ throw " Please specify -Id or -Name or -TagName or -ClassName"
259
+ }
260
+
261
+ $WebDriverWait = New-Object - TypeName OpenQA.Selenium.Support.UI.WebDriverWait($Driver , (New-TimeSpan - Seconds $Timeout ))
225
262
$Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions ]::ElementExists($TargetElement )
226
263
$WebDriverWait.Until ($Condition )
227
264
}
0 commit comments