0

I need to fill the login form by VBA code. I could not get any reaction on any combination of ".Click" method so i've tried to fill the form and then call JS submitting function but always get this error (as a VBA Error Message Box):

Could not complete the operation due to error 80020101

On the .jsp page there are following elements to interact with:

The form itself:

<form id="LoginViewForm" onsubmit="checkOnSubmit(this); return false;"
method="POST" name="LoginViewForm" action="LoginViewController.jsp">
<input type="HIDDEN" name="ControllerAction">
<input type="HIDDEN" name="loginPassword">
<input type="HIDDEN" name="newPassword">

Input boxes are the following:

        <td>
            <input name="loginUser" size="20" maxlength="18" type="text"
             tabindex="1" class="inputField" onfocus="this.select();">
        </td>

        <td>
            <input name="dspLoginPassword" size="20" maxlength="18"
            type="password" tabindex="2" class="inputField"
            onfocus="this.select();" autocomplete="off">
        </td>

There is a button, which should be clicked to submit a form:

<table id="buttonID1" border="1" cellspacing="0" cellpadding="0"
class="buttonBorderEmphasized">
 <tbody><tr>
  <td id="buttonEmphasized" nowrap="yes"class="buttonTextEmphasized">
   <a href="javascript:submitLogin (document.LoginViewForm);"
   tabindex="3">&nbsp;&nbsp;
   Login&nbsp;&nbsp;</a>
</td></tr></tbody></table>

And there is following script function, which is started by the button above:

 function submitLogin(form)
 {

  if(validateLogin()) {

    window.document.body.style.cursor = 'progress';
    showStatusMessage();
    form.ControllerAction.value = 'Login';
    form.submit();
    return;

  } else resetSubmitted(); return;

} 

I'm trying following code to handle with it (have tried different variants of calling java script, this is final one, but still doesn't work):

 Set objFormMain = IEDoc.Frames("i2ui_shell_content").Document _
 .Frames("results").Document.forms("LoginViewForm")

With objFormMain
    .Elements("LoginUser").Value = 1
    .Elements("dspLoginPassword").Value = 1
    IE.Document.all.Item
    Call IE.Document.parentWindow.execScript("submitLogin(document.LoginViewForm)", "JavaScript")
    .submit
End With

The error itself returns at line "Call IE.Document.parentWindow.execScript("submitLogin(document.LoginViewForm)", "JavaScript")"

Any ideas how to modify the code to make it work?

laooglee
  • 137
  • 13
  • This error means there's a JavaScript error on the page - it has nothing to do with VBA/Java/JSP etc. Please get the error from the browser console and paste it here. Also see http://stackoverflow.com/questions/10903989/could-not-complete-the-operation-due-to-error-80020101-ie – Charlie Apr 20 '16 at 15:16
  • Yes, i've read this article, but have nothing to do with it :( No some comments or "//" symbols to add or remove. And, btw, entering everything manually and pressing the button generates no error. Or it doesn't mean anything? – laooglee Apr 20 '16 at 15:20
  • And actually, i've get this error in the VBA editor itself, so probably i'm sending some arguments somehow wrong. – laooglee Apr 20 '16 at 15:26
  • Right the SO question was merely showing that error 80020101 is related to JS. I agree if you can't get the error when doing it manually it's with VBA. But you should be able to pause the code on the error and check the IE console for the JS error. – Charlie Apr 20 '16 at 15:30
  • Erm, unfortunately i've got "Permission denied" error to access any Developer tools via IE. I've used Chrome to get tag names and properties. – laooglee Apr 20 '16 at 15:36

2 Answers2

0

The Permission Denied issues appears be well documented elsewhere e.g. here. My recommendation is that you need to get access to the actual JS error from within IE to figure out what's wrong.

Of course there are other ways to do this type of things namely to use a tool called Selenium which has bindings in many languages including VBA. The advantages to a tool like Selenium is that 1) It's the defacto choice for this type of thing and 2) it works on all browsers not just IE.

Community
  • 1
  • 1
Charlie
  • 2,004
  • 6
  • 20
  • 40
0

Well, thanks everyone for concerns, I've found what I need.

Actually, I didn't need to address the script directly. I've just had to dig a bit deeper in trying to use .Click method.

Initially I supposed, that only some "button" tags may be accessed by ".Click", but then I found that you may use it on < a ...> tag as well.

So, i've just used following code:

IEDoc.Frames("i2ui_shell_content").Document.Frames("results") _
.Document.forms("LoginViewForm").GetElementsByTagName("a")(1).Click

Which accordingly run JS, contained in this tag:

<a href="javascript:submitLogin (document.LoginViewForm);"tabindex="3">
laooglee
  • 137
  • 13