Unable to insert text in a textbox on a website using Powershell

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 2 months ago.

  • Author
    Posts
  • #72875

    JohnJacob
    Participant

    I'm trying to insert text into the textbox of a website but I seem to be doing something incorrect because I keep getting an error in the Powershell ISE. The code I'm using is:

    ($ie.Document.DocumentElement.getElementsByClassName('web-password-input') | Select-Object -First 1).value = 'asdf'

    The error it shows in the ISE is:

    The property 'Value' cannot be found on this object. Verify that the property exists and can be set.
    At C:\Users\file.ps1:53 char:5
    +     ($ie.Document.DocumentElement.getElementsByClassName('web-passwor ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : PropertyNotFound

    I used this code earlier in the project and it worked correctly, granted this is to submit a button and not insert text.

    $fs = $ie.Document.DocumentElement.getElementsByClassName('right-nav button button-link last') | Select-Object -first 1
    $fs.click()

    The HTML code that I'm trying to target is:

    Any help would be greatly appreciated.

  • #72877

    Don Jones
    Keymaster

    So, here's the fun part about that ancient, deprecated, soon-to-be-discontinued Internet Explorer COM object: it sucks.

    It's very possible that your Select-Object is changing things enough that .NET can no longer wedge everything through the Interop layer. I might do ....getElementByClassName('whatever')[0] instead, 0 being the first item, followed by .value() or whatever.

    But this kind of 'interactive page manipulation' is about the furthest thing from PowerShell's strengths, unfortunately. It truly is based on an outdated technology that hasn't received any improvements almost since before PowerShell was launched. So... it's tough to work with, for sure.

You must be logged in to reply to this topic.