|
3 | 3 | function Start-SeChrome { |
4 | 4 | Param( |
5 | 5 | [Parameter(Mandatory = $false)] |
6 | | - [array]$Arguments |
| 6 | + [array]$Arguments, |
| 7 | + [switch]$HideVersionHint |
7 | 8 | ) |
8 | 9 | if($Arguments) { |
9 | 10 | $Chrome_Options = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeOptions" |
10 | 11 | $Chrome_Options.AddArguments($Arguments) |
11 | 12 | } |
| 13 | + if(!$HideVersionHint) |
| 14 | + { |
| 15 | + Write-Host "Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'" -ForegroundColor Yellow |
| 16 | + } |
12 | 17 | New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList $Chrome_Options |
13 | 18 | } |
14 | 19 |
|
@@ -121,9 +126,18 @@ function Invoke-SeClick { |
121 | 126 |
|
122 | 127 | } |
123 | 128 |
|
| 129 | +function Get-SeKeys { |
| 130 | + |
| 131 | + [OpenQA.Selenium.Keys] | Get-Member -MemberType Property -Static | Select-Object -Property Name,@{N = "ObjectString"; E = {"[OpenQA.Selenium.Keys]::$($_.Name)"}} |
| 132 | +} |
| 133 | + |
124 | 134 | function Send-SeKeys { |
125 | 135 | param([OpenQA.Selenium.IWebElement]$Element, [string]$Keys) |
126 | | - |
| 136 | + |
| 137 | + foreach($Key in @(Get-SeKeys).Name) |
| 138 | + { |
| 139 | + $Keys = $Keys -replace "{{$Key}}", [OpenQA.Selenium.Keys]::$Key |
| 140 | + } |
127 | 141 | $Element.SendKeys($Keys) |
128 | 142 | } |
129 | 143 |
|
@@ -184,3 +198,29 @@ function Save-SeScreenshot { |
184 | 198 | $Screenshot.SaveAsFile($Path, $ImageFormat) |
185 | 199 | } |
186 | 200 | } |
| 201 | + |
| 202 | +function Wait-SeElementExists { |
| 203 | + param( |
| 204 | + $Driver, |
| 205 | + $Timeout = 30, |
| 206 | + $Id, |
| 207 | + $Name |
| 208 | + ) |
| 209 | + if($Id) |
| 210 | + { |
| 211 | + $TargetElement = [OpenQA.Selenium.By]::Id($Id) |
| 212 | + } |
| 213 | + elseif($Name) |
| 214 | + { |
| 215 | + $TargetElement = [OpenQA.Selenium.By]::Name($Name) |
| 216 | + } |
| 217 | + else |
| 218 | + { |
| 219 | + throw "Please specify -Id or -Name" |
| 220 | + } |
| 221 | + $WebDriverWait = New-Object OpenQA.Selenium.Support.UI.WebDriverWait $Driver, ($Timeout * 10000000) # ticks |
| 222 | + $Condition = [OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists($TargetElement) |
| 223 | + $WebDriverWait.Until($Condition) |
| 224 | +} |
| 225 | + |
| 226 | + |
0 commit comments