powershell script open webpage , click specific link
i trying write script opens specific webpage , clicks specific link. cannot edit html embedded on device (digital projector). have seen question asked , answered before unable work. have tried copying code other serverfault answers , keep getting 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 link trying click calling 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 in iframe on simple webpage. control panel nec nc1200c projector else working on same system. trying write script pull web interface of projector , turn on automatically. include of code makes pages in question below.
this html of page being called: having trouble inserting code code markup
links similar questions:
click hyperlink using powershell
well, make works in lab.
assuming sample html file :
<html> <body> <script type="text/javascript"> function poweron(){ document.location.href="http://google.com"; } </script> <a href="javascript:onclick=poweron();"><img src="http://www.google.fr/url?source=imglanding&ct=img&q=http://www.picturesnew.com/media/images/e4454c8df9.png&sa=x&ei=lbhpvazqg6a07ga6l4ja&ved=0cakq8wc&usg=afqjcnfnfxiwemexihvyqvfhmmgxofcjfg" width="75" height="32" border="0" name="power_on"></a> </body> </html>
then powershell script :
$ie = new-object -com internetexplorer.application $ie.visible=$true $ie.navigate('http://192.168.108.130') $link=$ie.document.getelementsbytagname('a') | where-object {$_.href -eq "javascript:onclick=poweron();"} $link.click()
from there, when run powershell script redirected google if clicking on image.
i think main problem has -match
expression used. not sure why...but i've used -eq
instead.
i've add onclick
event in href
directive seems required call $link.click()
.
Comments
Post a Comment