diff --git a/src/Monocle.psd1 b/src/Monocle.psd1 index 8cdab1e..0f81047 100644 --- a/src/Monocle.psd1 +++ b/src/Monocle.psd1 @@ -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' diff --git a/src/Monocle.psm1 b/src/Monocle.psm1 index 693e302..19ee42c 100644 --- a/src/Monocle.psm1 +++ b/src/Monocle.psm1 @@ -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 diff --git a/src/Private/Elements.ps1 b/src/Private/Elements.ps1 index 6eadf13..fd858c6 100644 --- a/src/Private/Elements.ps1 +++ b/src/Private/Elements.ps1 @@ -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) { @@ -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 } diff --git a/src/lib/Microsoft.mshtml.dll b/src/lib/Microsoft.mshtml.dll new file mode 100644 index 0000000..46e2e0c Binary files /dev/null and b/src/lib/Microsoft.mshtml.dll differ