Log out of Web Page using Powershell

Welcome Forums General PowerShell Q&A Log out of Web Page using Powershell

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
3 years, 2 months ago.

  • Author
    Posts
  • #29160

    Participant
    Points: 1
    Rank: Member

    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

    Keymaster
    Points: 1,639
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Log out of Web Page using Powershell’ is closed to new replies.