none
Powershell click on span item RRS feed

  • Question

  • Hi,

    I am trying my Powershell script clicks on a button in a web page. The button is part of a menubar. It's the copy button

    Here is the code of the web page:

    <BODY style="margin: 0px" tabindex="-1" language=javascript onload="return window_onload()" onresize="return window_onresize()">
    
    <DIV id=Header style="display: block">
    	<TABLE class=MenuBar width=100% cellpadding=0 cellspacing=0 border=0>
    		<TR>
    			<TD NOWRAP>
    			&nbsp;<SPAN class=Menu onClick="CopyReport('The report data has been copied to the clipboard.')" onKeyPress="CheckKeyPressed2('The report data has been copied to the clipboard.')" onfocus="MenuFocus()" onblur="MenuBlur()" hidefocus=true title="Copies the report data and column headings to the Clipboard." tabindex=0 accesskey=1 id=mnuCopy>Copy</SPAN>&nbsp;


    Here is the code of my powershell script :

    $urlmira = "http://mira/smsReporting_STH/Report.asp?ReportID=594&computername="+ $pcnumold + "&Office=" + $local + "&Username=" + $name + "&NewPC=N/A"
    
    $ie = New-Object -comobject InternetExplorer.Application 
    $ie.visible = $true
    $ie.silent = $true
    $ie.Navigate($urlmira)
    while($ie.busy){Start-Sleep 1} 
    $copyBtn = $ie.Document.getElementsById("mnuCopy") | Where-Object {$_.innerText -eq 'Copy'} 
    $copyBtn.click() 

    And when I execute my code, it's return me an error :

    You cannot call a method on a null-valued expression.
    At C:\Temp\Scripts\CreationfeuilledeTravail.ps1:279 char:40
    + $copyBtn = $ie.Document.getElementsById <<<< ("mnuCopy") | Where-Object {$_.innerText -like '*Copy'}
        + CategoryInfo          : InvalidOperation: (getElementsById:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Tuesday, February 17, 2015 3:58 PM

Answers