Log out of Web Page using Powershell

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

  • Author
    Posts
  • #29160

    Valerie Knopfel
    Participant

    I am writing a PowerShell script that launches a site in IE, authenticates and logs into the web page which is working fine.
    But I wanted to log out of it (gracefully) rather than just closing ie.

    Below (bottom of this) is the element in the web page but I can't seem to get the right combination in PowerShell to log out of the web page. I tried:

    $IE.Document.getElementById("header:header_info:linklogout").onclick()

    But that didn't work – tried just a .click and then tried .return but none of those worked. If anyone can point me in the right direction – I'd greatly appreciate it!

    Element:
    id="header:header_info:linklogout" style="color: rgb(79, 33, 112); margin-right: 4px;" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('header:header_info'),{'header:header_info:linklogout':'header:header_info:linklogout'},");}return false" href="#">Logout

  • #29289

    Don Jones
    Keymaster

    It depends entirely on how the web page is designed. Normally, click() is the right method. However, since here the element is defining a JS response to click(), you could potentially try just calling that JS directly. It's going to be tricky, though, and you might not be able to get it to work. The IE COM object just wasn't designed for this kind of manipulation, and the fact that it has to go through .NET Interop into PowerShell makes it even more difficult. IE just wasn't designed with this kind of automation in mind. If sending a click() to the element didn't work, then you may be stuck.

You must be logged in to reply to this topic.