0

I'm trying to click on a button after inputing data in this field:

<input name="termoBuscaUsuarioAprovador" id="termoBuscaUsuarioAprovador" 
style="width: 240px;" onkeydown="javascript:var keyCode = event.keyCode ? 
event.keyCode : event.which ? event.which : event.charCode; if(keyCode == 13) { 
document.getElementById('buscaResponsavel').focus(); }" onkeypress="return 
desabilita(this, event);javascript:var keyCode = event.keyCode ? event.keyCode 
: event.which ? event.which : event.charCode; if(keyCode == 13) { document.getElementById('buscaResponsavel').focus(); }" type="text" value="">

I'm using this and it seems to work:

IE.Document.getElementById("termoBuscaUsuarioAprovador").Value = "xxxxxxx" 'Name

But when I try to click on the "Search" button below, a brief loading bar appears (exacly as if I was manualy clicking the button), but it doesn't show anything, it still remaings blank.

<input name="buscaUsuarioAprovador" id="buscaResponsavel" style="width: 100px;" onclick="pesquisar_dadosUsuarioAprovador(document.getElementById('termoBuscaUsuarioAprovador').value)" type="button" value="Buscar">

The code I'm using that makes the loading bar appears is:

IE.Document.getElementById("buscaResponsavel").Click

I don't know if i'm partially triggering the button because of that "onclick", or if it has something to do with the input field.

Thank you!

2 Answers 2

1

Its hard to answer your question without navigating webpage, but most common possibility is text box value triggers some function to perform so instead of just passing value to the text box you can use below methods Method 1:

  set Zip =  IE.Document.getElementById("termoBuscaUsuarioAprovador")
  Zip.Value = "XXXXX"   
  Dim event_onChange As Object
  Set event_onChange = ie_Doc.createEvent("HTMLEvents")
  event_onChange.initEvent "keypress", True, False
  Zip.dispatchEvent event_onChange

you can replace "Keypress" as "keydown" if it not works

Method 2:

   set Zip =  IE.Document.getElementById("termoBuscaUsuarioAprovador")
  Zip.Value = "XXXXX"
  Zip.FireEvent ("onkeypress")
or
  Zip.FireEvent ("onblur")

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

Method 1 gave me an error with "ie_doc", so I replaced it with IE.Document. But when I tested the code nothing happened in the website. Method 2 neither FireEvents triggered the button.
1

Have you tried .FireEvent to trigger the onclick?

IE.Document.getElementById("buscaResponsavel").FireEvent "onclick"

Perhaps sequence:

IE.Document.getElementById("buscaResponsavel").FireEvent "onkeypress"
'Set value however you are.....
IE.Document.getElementById("buscaResponsavel").FireEvent "onclick"

5 Comments

Forgot to mention that, yes I did, it had the same effect of .click (brief loading bar, but result is blank)
Did you try firing the other 2 events? Looks like needs keydown to enable focus
No luck. What do you mean by keydown?
The other events listed in the html for the element
oh, ok. But no results yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.