1
- [System.Reflection.Assembly ]::LoadFrom(" $PSScriptRoot \WebDriver.dll" )
2
- [System.Reflection.Assembly ]::LoadFrom(" $PSScriptRoot \WebDriver.Support.dll" )
3
-
1
+ [System.Reflection.Assembly ]::LoadFrom(" $PSScriptRoot \assemblies\WebDriver.dll" )
2
+ [System.Reflection.Assembly ]::LoadFrom(" $PSScriptRoot \assemblies\WebDriver.Support.dll" )
4
3
function Start-SeChrome {
5
4
New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver"
6
5
}
7
6
8
7
function Start-SeFirefox {
9
- New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver"
8
+ param ([Switch ]$Profile )
9
+
10
+ if ($Profile ) {
11
+ # Doesn't work....
12
+ $ProfilePath = Join-Path $PSScriptRoot " Assets\ff-profile\rust_mozprofile.YwpEBLY3hCRX"
13
+ $firefoxProfile = New-Object OpenQA.Selenium.Firefox.FirefoxProfile - ArgumentList ($ProfilePath )
14
+ $firefoxProfile.WriteToDisk ()
15
+ New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver" - ArgumentList $firefoxProfile
16
+ }
17
+ else {
18
+ $Driver = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver"
19
+ $Driver.Manage ().Timeouts().ImplicitWait = [TimeSpan ]::FromSeconds(10 )
20
+ $Driver
21
+ }
22
+
10
23
}
11
24
12
25
function Stop-SeDriver {
@@ -36,7 +49,9 @@ function Find-SeElement {
36
49
[Parameter (ParameterSetName = " ByLinkText" )]
37
50
$LinkText ,
38
51
[Parameter (ParameterSetName = " ByTagName" )]
39
- $TagName )
52
+ $TagName ,
53
+ [Parameter (ParameterSetName = " ByXPath" )]
54
+ $XPath )
40
55
41
56
Process {
42
57
@@ -72,13 +87,30 @@ function Find-SeElement {
72
87
if ($PSCmdlet.ParameterSetName -eq " ByTagName" ) {
73
88
$Target.FindElements ([OpenQA.Selenium.By ]::TagName($TagName ))
74
89
}
90
+
91
+ if ($PSCmdlet.ParameterSetName -eq " ByXPath" ) {
92
+ $Target.FindElements ([OpenQA.Selenium.By ]::XPath($XPath ))
93
+ }
75
94
}
76
95
}
77
96
78
97
function Invoke-SeClick {
79
- param ([OpenQA.Selenium.IWebElement ]$Element )
98
+ param (
99
+ [Parameter (Mandatory = $true , ValueFromPipeline = $true )]
100
+ [OpenQA.Selenium.IWebElement ]$Element ,
101
+ [Parameter ()]
102
+ [Switch ]$JavaScriptClick ,
103
+ [Parameter ()]
104
+ $Driver
105
+ )
106
+
107
+ if ($JavaScriptClick ) {
108
+ $Driver.ExecuteScript (" arguments[0].click()" , $Element )
109
+ } else {
110
+ $Element.Click ()
111
+ }
80
112
81
- $Element .Click ()
113
+
82
114
}
83
115
84
116
function Send-SeKeys {
@@ -118,4 +150,27 @@ function Get-SeElementAttribute {
118
150
Process {
119
151
$Element.GetAttribute ($Attribute )
120
152
}
121
- }
153
+ }
154
+
155
+ function Invoke-SeScreenshot {
156
+ param ($Driver , [Switch ]$AsBase64EncodedString )
157
+
158
+ $Screenshot = [OpenQA.Selenium.Support.Extensions.WebDriverExtensions ]::TakeScreenshot($Driver )
159
+ if ($AsBase64String ) {
160
+ $Screenshot.AsBase64EncodedString
161
+ }
162
+ }
163
+
164
+ function Save-SeScreenshot {
165
+ param (
166
+ [Parameter (ValueFromPipeline = $true , Mandatory = $true )]
167
+ [OpenQA.Selenium.Screenshot ]$Screenshot ,
168
+ [Parameter (Mandatory = $true )]
169
+ [string ]$Path ,
170
+ [Parameter ()]
171
+ [OpenQA.Selenium.ScreenshotImageFormat ]$ImageFormat = [OpenQA.Selenium.ScreenshotImageFormat ]::Png)
172
+
173
+ Process {
174
+ $Screenshot.SaveAsFile ($Path , $ImageFormat )
175
+ }
176
+ }
0 commit comments