IE automation with javascript button

by megamorf at 2012-10-18 16:27:04

Hello everybody,

I’m trying to automate uploading logfiles to the Citrix Autosupport website. You can upload logfiles for XenDesktop, XenServer, XenApp, NetScaler and it will scan them for hundreds of known issues.

My problem is that I can’t get the login button click method to work because there’s a lot of javascript involved. The website is and I hope you are able to help me figure out how to do it.

$ie = new-object -com InternetExplorer.Application
while ($ie.Busy -eq $true){Start-Sleep -Milliseconds 1000}
$ie.Document.getElementById("username").value = "mycitrixusername"
$ie.Document.getElementById("password").value = "supersecretpassword"

Here’s the login button
<td align="left">
<input id="btnLogOn" type="button" style="width:230px" value="Let’s Go"/>
<input type="hidden" id="txtNext" value=""/>

Here are the functions from the last javascript block of the page that are relevant (in my opinion):
var logon = function() {
var err = false;
var username = $.trim(txtUsername.val());
var password = $.trim(txtPassword.val());
if (!username) {
errMessage.html("Username is required.");
err = true;
if (!password) {
errMessage.html("Password is required.");
err = true;
if (err) {;
return false;

var data = {};
data[txtUsername.attr(‘name’)] = username;
data[txtPassword.attr(‘name’)] = password;
if (ckbRememberMe.jSym_checkbox(‘isChecked’)) {
data[‘remember_me’] = true;

if (‘:visible’))

url : form.attr(‘action’),
type : form.attr(‘method’),
dataType : ‘json’,
data : data,
error : function() {
errMessage.html(‘Login not accepted. Please try again.’);;
success : function(res) {
if (res.result == ‘Ok’) {
_gaq.push([‘_trackEvent’, ‘Logon’, ‘Clicked’, ‘Homepage’]);
setTimeout(function () {
if (next && next != location.href) {
location.href = next;
} else {
}, 100);
} else {
errMessage.html(res.result ? res.result : ‘Invalid login. Please try again.’);;
return false;

var btnLogon = $(‘#btnLogOn’).jSym_button({
buttonType : ‘cta’,
buttonClick : logon

var form = $(‘#frmLogin’).keypress(function(evt) {
if (evt.which == 13) {
return false;
by DonJ at 2012-10-19 09:46:43
I’ve run into this a number of times, and have been told by folks smarter than me that it’s a limitation in the IE COM interface. In other words, it won’t do it. You could look into something like AutoIt to automate actually clicking the button with the mouse pointer.
by megamorf at 2012-10-19 13:33:49
Okay, to sum this up. I wasn’t able to automate the process because there’s way too much javascript involved after you logged in.

However, I managed to login by using an automation module called wasp

My code looks like this for the login process. That should work where there’s javascript logic behind a login button:

Import-Module wasp
$ie = New-Object -com InternetExplorer.Application
while ($ie.Busy -eq $true){Start-Sleep -Milliseconds 1000}

$IEProcess = Select-Window -Title "Citrix Auto Support*" #Retrieves all windows with the specified title

$ie.document.getElementById("username").value = "mycitrixusername"
$ie.document.getElementById("password").value = "supersecretpassword"
$IEProcess | Send-Keys "{Enter}" # Sends Enter button after username and password were entered
while ($ie.Busy -eq $true){Start-Sleep -Milliseconds 1000}
# do what you want after the login process has completed