-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize.ps1
235 lines (205 loc) · 7.3 KB
/
initialize.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
class Question # Question constructor
{
[string]$index
[string]$topic
[string]$type
[string]$question
[string]$option0
[string]$option1
[string]$option2
[string]$option3
[string]$option4
[string]$option5
[string]$option6
[string]$option7
[string]$explanation
[string]$answer0
[string]$answer1
[string]$answer2
[string]$answer3
[string]$score0
[string]$score1
[string]$score2
[string]$score3
Question() # Constructor
{
$this.index
$this.topic
$this.type
$this.question
$this.option0
$this.option1
$this.option2
$this.option3
$this.option4
$this.option5
$this.option6
$this.option7
$this.explanation
$this.answer0
$this.answer1
$this.answer2
$this.answer3
$this.score0
$this.score1
$this.score2
$this.score3
}
}
$Selector = New-Object psobject -Property @{
question = "Question #*"
;correct = "Correct Answer:*"
;explanation = "Explanation:*"
#;section = "- (Exam Topic*"
;options = @(
"A.*"
,"B.*"
,"C.*"
,"D.*"
,"E.*"
,"F.*"
,"G.*"
,"H.*"
)
;imageFormat = @(
"*.jpeg"
,"*.png"
)
;filter = @(
"Note: This question is part of a series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some question sets might have more than one correct solution, while others might not have a correct solution.<BR>After you answer a question in this section, you will NOT be able to return to it. As a result, these questions will not appear in the review screen.<BR>"
,"✑"
,"ג€`">"
)
;FilterType = @(
"*hotspot*"
,"*drag drop*"
)
class = @(
[pscustomobject]@{
QuestionNumber = "exam-question-card"
Topic = "question-title-topic"
Question = "card-text"
Options = "question-choices-container"
Answer = "correct-answer"
Explanation = "answer-description"
}
)
} # End of Selector object
# Add the working directory to the environment path.
# This is required for the ChromeDriver to work.
$workingPath = "$PSScriptRoot\selenium"
Write-Host "Set envPath to $workingPath"
if (($env:Path -split ';') -notcontains $workingPath) {
$env:Path += ";$workingPath"
}
Import-Module $workingPath\WebDriver.dll
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$chromeDriver.manage().timeouts().implicitWait = [System.TimeSpan]::FromSeconds([int]3)
function Get-SeleniumElement($xPath, $className) {
try {
if ($xPath.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::XPath($xPath)) }
elseif ($className.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::ClassName($className)) }
if ($result.count -gt 0) { return $result}
else { return $null}
}
catch{
Write-Error $_
}
}
function Click-SeleniumElementButton ($xPath, $className) {
try {
if ($xPath.length -gt 0) { $result = $ChromeDriver.FindElement([OpenQA.Selenium.By]::XPath($xPath)).click() }
elseif ($className.length -gt 0) { $result = $ChromeDriver.FindElement([OpenQA.Selenium.By]::ClassName($className)).click() }
if ($result.count -gt 0) { return $result}
else { return $null}
}
catch{
Write-Error $_
}
}
function Get-SeleniumElementText ($xPath, $className) {
try {
if ($xPath.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::XPath($xPath)).Text }
elseif ($className.length -gt 0) { $result = $ChromeDriver.FindElement([OpenQA.Selenium.By]::ClassName($className)).Text }
if ($result.count -gt 0) { return $result}
else { return $null}
}
catch{
Write-Error $_
}
}
function Get-SeleniumElementOuterHTML ($xPath, $className) {
try {
if ($xPath.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::XPath($xPath)).GetAttribute('outerHTML') }
elseif ($className.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::ClassName($className)).GetAttribute('outerHTML') }
if ($result.count -gt 0) { return $result}
else { return $null}
}
catch{
Write-Error $_
}
}
function Get-SeleniumElementInnerHTML ($xPath, $className) {
try {
if ($xPath.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::XPath($xPath)).GetAttribute('innerHTML') }
elseif ($className.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::ClassName($className)).GetAttribute('innerHTML') }
if ($result.count -gt 0) { return $result}
else { return $null}
}
catch{
Write-Error $_
}
}
function Get-SeleniumElementAttribute ($xPath, $className, $attribute) {
try {
if ($xPath.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::XPath($xPath)).GetAttribute($attribute) }
elseif ($className.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::ClassName($className)).GetAttribute($attribute) }
if ($result.count -gt 0) { return $result}
else { return $null}
}
catch{
Write-Error $_
}
}
function Get-SeleniumElementHref ($xPath, $className) {
try {
if ($xPath.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::XPath($xPath)).GetAttribute('href') }
elseif ($className.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::ClassName($className)).GetAttribute('href') }
if ($result.count -gt 0) { return $result}
else { return $null}
}
catch{
Write-Error $_
}
}
function Get-SeleniumElementSrc ($xPath) {
try {
if ($xPath.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::XPath($xPath)).GetAttribute('src') }
elseif ($className.length -gt 0) { $result = $ChromeDriver.FindElements([OpenQA.Selenium.By]::ClassName($className)).GetAttribute('src') }
if ($result.count -gt 0) { return $result}
else { return $null}
}
catch{
Write-Error $_
}
}
function Get-SeleniumElementChildren ($xPath, $ClassName) {
try {
if ($xPath.length -gt 0) { $element = $ChromeDriver.FindElements([OpenQA.Selenium.By]::XPath($xPath)) }
elseif ($className.length -gt 0) { $element = $ChromeDriver.FindElements([OpenQA.Selenium.By]::ClassName($className)) }
if ($element.Count -gt 0) { $result = $element.FindElements([OpenQA.Selenium.By]::XPath(".//*")) }
if ($result.count -gt 0) { return $result }
else { return $null}
}
catch{
Write-Error $_
}
}
function Remove-SpecialCharacters ( $string) {
$charactersToKeep =@("/", "\","!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "+", "=", "``", "<", ">", ",", ".", "?", "{", "}", "[", "]", "|", ";", ":")
[string]$ExcludeCharacters = foreach ($char in $charactersToKeep) {"/$char"}
$ExcludeCharacters = $ExcludeCharacters.Replace(" ", "")
$regex = '[^\p{L}\p{Nd}'
$regexString = $regex + $ExcludeCharacters
$string -replace $regexString, ''
}