Powershell script to open webpage and click a specific link
I am trying to write a script that opens up a specific webpage and clicks a specific link. I cannot edit the HTML as it is embedded on a device (Digital Projector). I have seen this question asked and answered before but I am unable to get it to work. I have even tried copying code from other serverfault answers and I keep getting the same or similar errors:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The PowerScript
$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("http://10.10.62.200/")
$link = @($ie.Document.getElementsByTagName('A')) | Where-Object {$_.href -match "`#javascript:powerOn()"}
$link.click()
Additional info & background
This is the link I am trying to click which is calling a javascript function:
<a href="javascript:powerOn();">
<img src="./img/power_on_g.png" width="75" height="32" border="0" name="power_on"></a>
This code is actually in an iframe on a very simple webpage. It is the control panel for an NEC NC1200C projector for anyone else working on this same system. I am trying to write a script to pull up the web interface of the projector and turn it on automatically. I will include all of the code that makes up the pages in question below.
This is the HTML of the page being called:
HAVING TROUBLE INSERTING CODE EVEN WITH CODE MARKUP
Links to similar questions:
Click a hyperlink using powershell
ie.busyorie.readystate -ne 4from your linked posts. You may need to do more to work with an iFrame. I'd be watching with Firebug or Chrome dev tools or IE Dev tools or Fiddler2 proxy to see what the JavaScript actually sends, and see if I could send that directly withInvoke-WebRequest, and without using IE at all.$ie = new-object -com "InternetExplorer.Application"and then do$ie.Visible = $trueand it will appear as a window, still being controlled by PowerShell. Then you can explore what $ie.Document,blahblah returns interactively, much easier and more fun than writing the script and guessing, finding it doesn't work, not knowing why.