Skip to content

Commit 33ff05f

Browse files
committed
1 parent 6cb9db8 commit 33ff05f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

Public/Get-SeElementAttribute.ps1

+31-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,38 @@ function Get-SeElementAttribute {
33
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
44
[OpenQA.Selenium.IWebElement]$Element,
55
[Parameter(Mandatory = $true)]
6-
[string]$Attribute
6+
[string[]]$Attribute
77
)
88
process {
9-
$Element.GetAttribute($Attribute)
9+
$AllAttributes = $Attribute.Count -eq 1 -and $Attribute[0] -eq '*'
10+
$ManyAttributes = $Attribute.Count -gt 1
11+
12+
if ($AllAttributes) {
13+
$AllAttributes = $Element.WrappedDriver.ExecuteScript('var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;', $Element)
14+
$Output = @{}
15+
16+
Foreach ($Att in $AllAttributes.Keys) {
17+
$value = $Element.GetAttribute($Att)
18+
if ($value -ne "") {
19+
$Output.$Att = $value
20+
}
21+
}
22+
[PSCustomObject]$Output
23+
}
24+
elseif ($ManyAttributes) {
25+
$Output = @{}
26+
Foreach ($Att in $Attribute) {
27+
$value = $Element.GetAttribute($Att)
28+
if ($value -ne "") {
29+
$Output.$Att = $value
30+
}
31+
}
32+
[PSCustomObject]$Output
33+
}
34+
else {
35+
$Element.GetAttribute($Attribute)
36+
}
37+
38+
1039
}
1140
}

0 commit comments

Comments
 (0)