none
While Trying to send Powershell Data to php form getting the Error: You cannot call a method on a null-valued expression RRS feed

  • คำถาม

  • Hi,

    I am trying to send the data of powershell to the registration form in php it is showing an error

    Code:

    Add-Type -AssemblyName Microsoft.VisualBasic

     $orderID= hostname
     $orderID1= (get-wmiobject -Class win32_bios).SerialNumber
     $OrderIDTextBox="hname" #  id of the Field Hostname in Registration form

    $OrderIDTextBox1="sno"# id of the field Serial no in Registration form
    $iterator = 1;
    $IE = New-Object -ComObject InternetExplorer.Application
    $ie.visible = $true
    $ie.navigate("http://localhost/asset.php")
    While ($IE.Busy -eq $true) {Start-Sleep -Milliseconds 2000} 

        Start-Sleep -Seconds 3
    $ie.Document.getElementById("$orderIDTextBox").value= "$OrderID"
    $ie.Document.getElementById("$orderIDTextBox1").value= "$OrderID1"

    error:

     

    You cannot call a method on a null-valued expression.
    At C:\Users\tpladmin\desktop\as.ps1:16 char:1
    + $ie.Document.getElementById("$orderIDTextBox").value= "$OrderID"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\tpladmin\desktop\as.ps1:17 char:1
    + $ie.Document.getElementById("$orderIDTextBox1").value= "$OrderID1"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Created the Value for the $ie with a Com Object. Web page with the url : http://localhost/asset.php is opening but unable to send the data to forms. Please help.

    Thanks in Advance.

     
    16 พฤศจิกายน 2562 19:17

ตอบทั้งหมด

  • This error occurs when you try to call a method that does not exist. As a troubleshooting step I would try $ie.document |gm to check if 'getElementById' method is visible.
    16 พฤศจิกายน 2562 20:33
  • Start by writing your code correctly. It will tell you the exact issue.

    $orderID= $env:COMPUTERNAME
    $orderID1 = (get-wmiobject -Class win32_bios).SerialNumber
    
    $ie = New-Object -ComObject InternetExplorer.Application
    $ie.visible = $true
    $ie.navigate('http://localhost/asset.php')
    While($ie.Busy){
        Start-Sleep 1
    } 
    
    Try{
        if($tb1 = $ie.Document.getElementById('hname')){
            $tb1.value= $OrderID
            if($tb2 = $ie.Document.getElementById('sno')){
                $tb2.value= $OrderID1
            }else{
                Write-Host 'Control "sno" not found'
            }
        }else{
            Write-Host 'Control "hname" not found'
        }
    }
    Catch{
        Throw $_
    }


    \_(ツ)_/



    16 พฤศจิกายน 2562 20:50
    ผู้ดูแล
  • Verify that your $ie.Document.getElementById("$orderIDTextBox") has actually returned an Element object. If it hasn't, then you can't get it's value. If there's no Element returned, are you sure you're using "hname" and "son" correctly? Perhaps they're names and not ID's? If they're names, use "getElementByName".

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)


    16 พฤศจิกายน 2562 21:05
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Lee

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    18 พฤศจิกายน 2562 5:56
    ผู้ดูแล