Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for IE9-11, and performance fix on Atrributes checking #9

Merged
merged 2 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.