Automating Internet Explorer via Excel VBA: manage mouse events

Hello everybody.

I usually apply a process for typing in site fields, very easy but effective.

For example, in a login mask:

IE.document.getElementsByTagName("INPUT")(0).Value = myLogin
IE.document.getElementsByTagName("INPUT")(1).Value = myPassword
IE.document.getElementsByTagName("button")(0).Click

Open in new window


But now I have bumped into a site with some peculiarities.

Exactly, I can type myId and myPassword with Vba, I can also click, but than the system gets the error

"All fields must be filled in"

as both login field and password field were not filled.

(I precise that it is an intranet site, so you cannot reach it.)

So, in analising the site architecture, I have come to the conclusion that I have to active an event, I mean a mouse click in the field, as manually I do when I access the site.

For example, the login field is as follows (consider the id is dynamic, each time is different):

<input id="in2598" class="bb-textbox" type="text" maxlength="18" value=""> 

Open in new window


But I have noticed when I manually click in the field, the html code changes in:

<input id="in2598" class="bb-textbox bb-textbox-focus" type="text" maxlength="18" value=""> 

Open in new window



Consider it is also a .zul site and something - to me it is not clear what - could be defined by ZKoss Javascript library.

So far, I have tried something like this, but unsuccesfully.


Dim HTMLdoc As HTMLDocument
Set HTMLdoc = IE.document

Dim evtclick As Object
Set evtclick = HTMLdoc.createEvent("HTMLEvents")

evtclick.initEvent "HTMLEvents", True, False

IE.document.getElementsByTagName("INPUT")(0).Value = myLogin
IE.document.getElementsByTagName("INPUT")(0).Value = dispatchEvent evtclick

Open in new window


Tell me if I have to get further details.
Paolo CrossiAdministrative employeeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Paolo

Have you tried submitting the login form rather than clicking the button?
IE.document.forms(0).submit

Open in new window

0
Paolo CrossiAdministrative employeeAuthor Commented:
Do you mean as follows?

IE.document.getElementsByTagName("INPUT")(0).Value = myId
IE.document.getElementsByTagName("INPUT")(1).Value = myCode
IE.document.forms(0).submit

Open in new window


"Run Time Error '424' object required" on the following row:

IE.document.forms(0).submit

Open in new window

0
NorieAnalyst Assistant Commented:
Paolo

That is what I mean but if that's the error message you are getting it would appear the page doesn't have any forms on it, well not 'standard' forms anyway.

You mention a  ZKoss Javascript library, do you have a link for that?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Paolo CrossiAdministrative employeeAuthor Commented:
I can try adding elements.

In the page html I can read:

<div id="k4UU_" class="bb-temp"></div>
<script class="bb-runonce" type="text/javascript">zk.pi=1;zkmx(
[0,'k4UU_',{dt:'z_1s50',cu:'/EXAMP;jsessionid=FC8F3D4E6DDC855F7FD11349F6AFC88D',uu:'/EXAMP/zkau;jsessionid=FC8F3D4E6DDC855F7FD11349F6AFC88D',ru:'/zulpages/login.zul'},[
['zul.wnd.Window','k4UU0',{$onOK:true,$$onSize:false,$$onMaximize:false,$$onOpen:false,$$onMinimize:false,$$onZIndex:false,$onClose:true,$$onMove:false,width:'350px',title:'SYSTEM MANAGEMENT,position:'center',border:'normal',mode:'modal'},[
['zul.box.Box','k4UU1',{prolog:'\n\t'},[
['zul.grid.Grid','k4UU2',{$$onRender:true,$$onDataLoading:true,$$onInnerWidth:false,$$onPageSize:true,$$onScrollPos:false,width:'330px',_topPad:0,emptyMessage:null,_totalSize:2,_offset:0},[
['zul.grid.Rows','k4UU3',{_offset:0,visibleItemCount:2},[
['zul.grid.Row','k4UU4',{width:'330px'},[
['zul.wgt.Label','k4UU5',{id:'userLabel',value:'User'},[]],
['zul.wgt.Div','k4UU6',{align:'center'},[
['zul.inp.Textbox','k4UU7',{id:'user',$$onError:false,$$onChange:false,prolog:'\n\t\t\t\t\t\t',maxlength:18},[]]]]]],
['zul.grid.Row','k4UU8',{width:'330px'},[
['zul.wgt.Label','k4UU9',{id:'passwordLabel',value:'Password'},[]],
['zul.wgt.Div','k4UUa',{align:'center'},[
['zul.inp.Textbox','k4UUb',{id:'password',prolog:'\n\t\t\t\t\t\t',maxlength:25,type:'password'},[]]]]]],
['zul.grid.Row','k4UUc',{id:'NewPasswordRow',visible:false,width:'330px'},[
['zul.wgt.Label','k4UUd',{id:'NewPasswordLabel',value:'New password'},[]],
['zul.wgt.Div','k4UUe',{align:'center'},[
['zul.inp.Textbox','k4UUf',{id:'newPassword',prolog:'\n\t\t\t\t\t\t',maxlength:25,type:'password'},[]]]]]],
['zul.grid.Row','k4UUg',{id:'confirmPasswordRow',visible:false,width:'330px'},[
['zul.wgt.Label','k4UUh',{id:'confirmPasswordLabel',value:'Confirm password'},[]],
['zul.wgt.Div','k4UUi',{align:'center'},[
['zul.inp.Textbox','k4UUj',{id:'confirmPassword',$onChange:true,prolog:'\n\t\t\t\t\t\t',maxlength:25,type:'password'},[]]]]]],
['zul.grid.Row','k4UUk',{visible:false,width:'330px'},[
['zul.wgt.Label','k4UUl',{id:'languageLabel',value:'Language'},[]],
['zul.wgt.Div','k4UUm',{align:'center'},[
['zul.inp.Combobox','k4UUn',{id:'language',$$onSelect:false,$$onError:false,$$onChange:false,$onChange:true,prolog:'\n\t\t\t\t\t\t'},[
['zul.inp.Comboitem','k4UUo',{},[]],
['zul.inp.Comboitem','k4UUp',{},[]]]]]]]]]]]],
['zul.wgt.Separator','k4UUq',{height:'10px',orient:'vertical'},[]],
['zul.wgt.Div','k4UUr',{align:'center'},[
['zul.wgt.Button','k4UUs',{id:'logInBtn',$onClick:true,prolog:'\n\t\t\t',label:'Enter'},[]],
['zul.wgt.Button','k4UUt',{id:'changePasswordBtn',visible:false,$onClick:true,prolog:'\n\t\t\t',label:'Change password'},[]]]],
['zul.wgt.Div','k4UUu',{align:'center'},[
['zul.wgt.Label','k4UUv',{id:'msg',style:'color:red;font-weight:bold',prolog:'\n\t\t\t'},[]]]]],'vertical']]]]]);
</script>

Open in new window


I'm trying to decrypt the code by using the following site:

https://www.zkoss.org/zkdemo/event
0
leakim971PluritechnicianCommented:
instead evtClick, use evtBlur or evtChange
0
Paolo CrossiAdministrative employeeAuthor Commented:
I could try, but I am not sure how to set the event (it is the first time I process in this way).

Dim HTMLdoc As HTMLDocument
Set HTMLdoc = IE.document

Dim evtChange As Object
Set evtChange = HTMLdoc.createEvent("HTMLEvents")

evtChange.initEvent "change", True, False


Dim Storesel As HTMLSelectElement

    Set Storesel = HTMLdoc.getElementsByTagName("input")(0)
    Storesel.Focus
    Storesel.Value = myId
    Storesel.dispatchEvent evtChange

Open in new window


It does not seem correct, becuase of the "Run-time error 438: Object doesn't support this property" on the following line:

Storesel.Value = myId

Open in new window

0
NorieAnalyst Assistant Commented:
Is Storesel a dropdown/combobox/listbox?
0
leakim971PluritechnicianCommented:
It does not seem correct, becuase of the "Run-time error 438: Object doesn't support this property" on the following line:

so now, you don't know how to set the value of the textbox ?
0
Paolo CrossiAdministrative employeeAuthor Commented:
Consider this just an idea (I have done some arrangements).
login-mask.png
0
leakim971PluritechnicianCommented:
try this :
IE.document.getElementsByTagName("INPUT")(0).Focus
IE.document.getElementsByTagName("INPUT")(0).Value = myLogin
IE.document.getElementsByTagName("INPUT")(0).Blur

IE.document.getElementsByTagName("INPUT")(1).Focus
IE.document.getElementsByTagName("INPUT")(1).Value = myPassword
IE.document.getElementsByTagName("INPUT")(1).Blur

IE.document.getElementsByTagName("button")(0).Click

Open in new window


And this :

IE.document.getElementsByTagName("INPUT")(0).Value = myLogin
IE.document.getElementsByTagName("INPUT")(1).Value = myPassword

Dim evt
Set evt = doc.createEvent("HTMLEvents")
evt.initEvent "change", False, True
e.dispatchEvent evt

IE.document.getElementsByTagName("button")(0).Click

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paolo CrossiAdministrative employeeAuthor Commented:
I'm testing this:

IE.document.getElementsByTagName("INPUT")(0).Focus
IE.document.getElementsByTagName("INPUT")(0).Value = myLogin
IE.document.getElementsByTagName("INPUT")(0).Blur

IE.document.getElementsByTagName("INPUT")(1).Focus
IE.document.getElementsByTagName("INPUT")(1).Value = myPassword
IE.document.getElementsByTagName("INPUT")(1).Blur

IE.document.getElementsByTagName("button")(0).Click

Open in new window


and it seems to work fine.

I will confirm you as soon as I finish the tests.
0
Paolo CrossiAdministrative employeeAuthor Commented:
I confirm: the following is ok:
IE.document.getElementsByTagName("INPUT")(0).Focus
IE.document.getElementsByTagName("INPUT")(0).Value = myLogin
IE.document.getElementsByTagName("INPUT")(0).Blur

IE.document.getElementsByTagName("INPUT")(1).Focus
IE.document.getElementsByTagName("INPUT")(1).Value = myPassword
IE.document.getElementsByTagName("INPUT")(1).Blur

IE.document.getElementsByTagName("button")(0).Click

Open in new window


The second one doesn't work for me:
IE.document.getElementsByTagName("INPUT")(0).Value = myLogin
IE.document.getElementsByTagName("INPUT")(1).Value = myPassword

Dim evt
Set evt = doc.createEvent("HTMLEvents")
evt.initEvent "change", False, True
e.dispatchEvent evt

IE.document.getElementsByTagName("button")(0).Click

Open in new window


with error 404 object required on row:
e.dispatchEvent evt

Open in new window


Anyway, for me is enough to go further: thank you.
1
Paolo CrossiAdministrative employeeAuthor Commented:
Able of clicking in the field as manually happens.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.