Skip to content

Commit 1429ff6

Browse files
committed
Adding module
1 parent e625f65 commit 1429ff6

File tree

5 files changed

+167
-0
lines changed

5 files changed

+167
-0
lines changed

Selenium.psm1

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
[System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\WebDriver.dll")
2+
[System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\WebDriver.Support.dll")
3+
4+
<#
5+
.SYNOPSIS
6+
Starts a Selenium Chrome driver
7+
8+
.DESCRIPTION
9+
Starts a Selenium Chrome driver
10+
11+
.EXAMPLE
12+
Start-SeChrome
13+
#>
14+
function Start-SeChrome {
15+
New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver"
16+
}
17+
18+
<#
19+
.SYNOPSIS
20+
Starts a Selenium Firefox driver
21+
22+
.DESCRIPTION
23+
Starts a Selenium Firefox driver
24+
25+
.EXAMPLE
26+
Start-SeFirefox
27+
#>
28+
function Start-SeFirefox {
29+
New-Object -TypeName "OpenQA.Selenium.Firefox.FirefoxDriver"
30+
}
31+
32+
<#
33+
.SYNOPSIS
34+
Stops a Selenium driver.
35+
36+
.DESCRIPTION
37+
Stops a Selenium driver.
38+
39+
.PARAMETER Driver
40+
The driver to stop.
41+
#>
42+
function Stop-SeDriver {
43+
param($Driver)
44+
45+
$Driver.Dispose()
46+
}
47+
48+
<#
49+
.SYNOPSIS
50+
Navigates to a url.
51+
52+
.DESCRIPTION
53+
Navigates to a url.
54+
55+
.PARAMETER Driver
56+
The driver to navigate with. See Start-SeChrome and Start-SeFirefox.
57+
58+
.PARAMETER Url
59+
The URL to navigate to.
60+
61+
.EXAMPLE
62+
Enter-SeUrl -Url https://www.google.com -Driver (Start-SeChrome)
63+
#>
64+
65+
function Enter-SeUrl {
66+
param($Driver, $Url)
67+
68+
$Driver.Navigate().GoToUrl($Url)
69+
}
70+
71+
<#
72+
.SYNOPSIS
73+
Find an element in the currently loaded page.
74+
75+
.DESCRIPTION
76+
Find an element in the currently loaded page.
77+
78+
.PARAMETER Driver
79+
The driver to navigate with. See Start-SeChrome and Start-SeFirefox.
80+
81+
.PARAMETER Name
82+
The name of the element to find.
83+
84+
.PARAMETER Id
85+
The Id of the element to find.
86+
87+
.PARAMETER ClassName
88+
The ClassName of the element to find.
89+
90+
.PARAMETER LinkText
91+
The LinkText of the element to find.
92+
93+
.EXAMPLE
94+
$Element = Find-SeElement -Driver $Driver -Id "MyTextbox"
95+
#>
96+
function Find-SeElement {
97+
param(
98+
[Parameter()]
99+
$Driver,
100+
[Parameter(ParameterSetName = "ByName")]
101+
$Name,
102+
[Parameter(ParameterSetName = "ById")]
103+
$Id,
104+
[Parameter(ParameterSetName = "ByClassName")]
105+
$ClassName,
106+
[Parameter(ParameterSetName = "ByLinkText")]
107+
$LinkText)
108+
109+
Process {
110+
if ($PSCmdlet.ParameterSetName -eq "ByName") {
111+
$Driver.FindElement([OpenQA.Selenium.By]::Name($Name))
112+
}
113+
114+
if ($PSCmdlet.ParameterSetName -eq "ById") {
115+
$Driver.FindElement([OpenQA.Selenium.By]::Id($Id))
116+
}
117+
118+
if ($PSCmdlet.ParameterSetName -eq "ByLinkText") {
119+
$Driver.FindElement([OpenQA.Selenium.By]::LinkText($LinkText))
120+
}
121+
122+
if ($PSCmdlet.ParameterSetName -eq "ByClassName") {
123+
$Driver.FindElement([OpenQA.Selenium.By]::ClassName($ClassName))
124+
}
125+
}
126+
}
127+
128+
<#
129+
.SYNOPSIS
130+
Clicks an element
131+
132+
.DESCRIPTION
133+
Clicks an element
134+
135+
.PARAMETER Element
136+
The element to click.
137+
138+
.EXAMPLE
139+
Invoke-SeClick -Element $Element
140+
#>
141+
function Invoke-SeClick {
142+
param([OpenQA.Selenium.IWebElement]$Element)
143+
144+
$Element.Click()
145+
}
146+
147+
<#
148+
.SYNOPSIS
149+
Sends keys to an element
150+
151+
.DESCRIPTION
152+
Sends keys to an element
153+
154+
.PARAMETER Element
155+
The element to send keys to.
156+
157+
.PARAMETER Keys
158+
The keys to send.
159+
160+
.EXAMPLE
161+
Send-SeKeys -Element $Element -Keys "Hey, there!"
162+
#>
163+
function Send-SeKeys {
164+
param([OpenQA.Selenium.IWebElement]$Element, [string]$Keys)
165+
166+
$Element.SendKeys($Keys)
167+
}

WebDriver.Support.dll

50.5 KB
Binary file not shown.

WebDriver.dll

1.69 MB
Binary file not shown.

chromedriver.exe

6.61 MB
Binary file not shown.

geckodriver.exe

5.77 MB
Binary file not shown.

0 commit comments

Comments
 (0)