Skip to content

Commit

Permalink
Merge pull request #9 from Badgerati/develop
Browse files Browse the repository at this point in the history
Fix for IE9-11, and performance fix on Atrributes checking
  • Loading branch information
Badgerati committed Oct 7, 2019
2 parents 990d93c + 4e6761c commit c565782
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Monocle.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'Monocle.psm1'

# Version number of this module.
ModuleVersion = '0.12.3'
ModuleVersion = '0.13.0'

# ID used to uniquely identify this module
GUID = '9dc3c8a1-664d-4253-a5d2-920250d3a15f'
Expand Down
9 changes: 8 additions & 1 deletion src/Monocle.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# load private functions
# root path to module
$root = Split-Path -Parent -Path $MyInvocation.MyCommand.Path

# get the path to the libraries and load them
$libraries = Join-Path $root 'lib'
$library = Join-Path $libraries 'Microsoft.mshtml.dll'
[System.Reflection.Assembly]::LoadFrom($library) | Out-Null

# load private functions
Get-ChildItem "$($root)/Private/*.ps1" | Resolve-Path | ForEach-Object { . $_ }

# get current functions to import public functions
Expand Down
21 changes: 17 additions & 4 deletions src/Private/Elements.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,29 @@ function Get-MonocleElementByTagName
$document = $Browser.Document

# get all elements for the tag
Write-Verbose -Message "Finding element with tag <$TagName>"
$elements = $document.IHTMLDocument3_getElementsByTagName($TagName)
$id = $TagName.ToLowerInvariant()

# if we have attribute info, attempt to get an element
if ($PSCmdlet.ParameterSetName -ieq 'Attribute')
{
Write-Verbose -Message "Finding element with tag <$TagName>, attribute '$AttributeName' with value '$AttributeValue'"
Write-Verbose -Message "Filtering $($elements.Length) elements by attribute '$AttributeName' with value '$AttributeValue'"
$found = $false
$justFirst = [string]::IsNullOrWhiteSpace($ElementValue)

$elements = $elements |
Where-Object { $_.getAttribute($AttributeName) -imatch $AttributeValue }
$elements = @(foreach ($element in $elements) {
if ($element.getAttribute($AttributeName) -inotmatch $AttributeValue) {
continue
}

$found = $true
$element

if ($found -and $justFirst) {
break
}
})

# throw error if can't find element
if ((Test-MonocleElementNull -Element ($elements | Select-Object -First 1)) -and !$NoThrow) {
Expand All @@ -148,7 +161,7 @@ function Get-MonocleElementByTagName

if (![string]::IsNullOrWhiteSpace($ElementValue))
{
Write-Verbose -Message "Finding element with tag <$TagName>, and value '$ElementValue'"
Write-Verbose -Message "Filtering $($elements.Length) elements with tag <$TagName>, and value '$ElementValue'"

$element = $elements |
Where-Object { $_.value -imatch $ElementValue }
Expand Down
Binary file added src/lib/Microsoft.mshtml.dll
Binary file not shown.

0 comments on commit c565782

Please sign in to comment.