Reputation: 33
I'm having such a hard time making this work out. Here is my problem.
I have created a script that several people should use and it doesnt work for any of them. Just in my machine.
So I thought it should be a library or something and decided to install visual studio 2015, just to test if it worked. And it did!
Sadly, I had to remove it as my company has a limited amount of serials for visual studio, and it stopped working.
I then decided to try to install several programs that came along with VS but no success. I installed Visual c++ from 2005 to 2015, .net 3.5, 4.5 , 4.6 and 4.7, and still no luck.
What I'm missing? Can anyone help me out with this?
Part of the code im using:
$IE = New-Object -ComObject InternetExplorer.Application -ErrorAction 0
$URL = 'www.site.com'
$IE.Visible = $true
$IE.Navigate($URL)
$ShellWindows = (New-Object -ComObject Shell.Application).Windows()
$Tabs = $ShellWindows | Where-Object {$_.Name -eq "Internet Explorer"}
$web = $tabs.Document.IHTMLDocument3_getElementsByTagName('Span')
And the error I'm getting:
Method invocation failed because [System.__ComObject] doesn't contain a method named 'IHTMLDocument3_getElementsByTagName'.
At line:103 char:2
+ $web = $tabs.Document.IHTMLDocument3_getElementsByTagName('Span')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (IHTMLDocument3_getElementsByTagName:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Upvotes: 1
Views: 3122
Reputation: 2625
Why you have put ?
$ShellWindows = (New-Object -ComObject Shell.Application).Windows()
I also made same change yesterday Wasted lots of time
Directly take
$IE.Document.getElementsByTagName("span")
check probably would run
Upvotes: 0
Reputation: 6860
This would be a another way to get the spans. Avoid using IHTMLDocuments when you can. They are just the versions of the default Com.Document and they are numbered in the order they were created. I honestly cant think of a use other then for rare backward compatibility that you should ever even look at them. Using the default Document will allow you to write scripts for what the user has instead of what you think they have.
$IE = New-Object -ComObject InternetExplorer.Application -ErrorAction 0
$URL = 'www.google.com'
$IE.Visible = $true
$IE.Navigate($URL)
while($IE.Document.readyState -ne "Complete"){
sleep -Milliseconds 100
}
$spans = $IE.Document.getElementsByTagName("span")
Upvotes: 3