How go to a Web page and fill the field?

Add-in Express™ Support Service
That's what is more important than anything else

How go to a Web page and fill the field?
 
Vadim Usmanov


Guest


Hi!
I need to go to a Web page, wait while the page be downloaded and fill the field on this page.
But the field isn't to be found and filled. It seems that getElementById occurs before the page is loaded. What's wrong?

Public Class IEModule

Private Sub AdxieCommandGoogleTranslate_OnClick(sender As System.Object, htmlDoc As System.Object) Handles AdxieCommandGoogleTranslate.OnClick

        Const navOpenInNewTab = 2048 
        Me.IEApp.Navigate(myURL, navOpenInNewTab) 'Navigate

        While Me.IEApp.Busy 
            Threading.Thread.Sleep(200) 'wait
        End While

        Dim MyField = Me.HTMLDocument.getElementById("source") 'Find the field on the html-page by Id
        If (MyField IsNot Nothing) Then 
            MyField.Value = TextForTranslate
        End If
End Sub
Posted 12 Jul, 2013 14:37:43 Top
SilverStr




Posts: 28
Joined: 2013-03-31
Why not hook DocumentComplete2, wait until rootDocLoaded is true and then conduct the call to getElementById?
Posted 12 Jul, 2013 15:56:39 Top
Andrei Smolin


Add-in Express team


Posts: 18948
Joined: 2006-05-11
Thank you SilverStr!

Hello Vadim,

Does the solution suggested by SilverStr suits you?


Andrei Smolin
Add-in Express Team Leader
Posted 17 Jul, 2013 02:49:03 Top
Vadim Usmanov


Guest


Thank you for your help.
I tried this way but could not solve the problem.

For some reason, I can not pass value of var TextForTranslate from Sub AdxieCommandGoogleTranslate_OnClick to Sub IEModule_DocumentComplete


Public Class IEModule  
 
Private Sub AdxieCommandGoogleTranslate_OnClick(sender As System.Object, htmlDoc As System.Object) Handles AdxieCommandGoogleTranslate.OnClick 

        Const navOpenInNewTab = 2048   
        Me.IEApp.Navigate(myURL, navOpenInNewTab) 'Navigate  

       TextForTranslate  = "Test test?Â?Ð?í
 
End Sub 

Dim TextForTranslate  As String

Private Sub IEModule_DocumentComplete(pDisp As Object, url As String) Handles Me.DocumentComplete
   
       Dim DocURL = Me.HTMLDocument.url 
       Dim TabDomen = Me.HTMLDocument.domain 
        If TabDomen = "translate.google.ru" Then
           Dim MyField = Me.HTMLDocument.getElementById("source") 'Find the field on the html-page by Id
           If (MyField IsNot Nothing) Then 
              MyField.Value = TextForTranslate
       	   End If

       End If
    End Sub

Posted 19 Jul, 2013 08:57:57 Top
Andrei Smolin


Add-in Express team


Posts: 18948
Joined: 2006-05-11
Hi Vadim,

This occurs because you open a new tab and the DocumentComplete event occurs in the new module instance; that instance has TextForTranslate empty.

I suggest that you check the sections "Windowing and Threading" and also "Instancing", see the PDF file in the folder {Add-in Express}\Docs on your development PC.


Andrei Smolin
Add-in Express Team Leader
Posted 19 Jul, 2013 09:27:09 Top
Vadim Usmanov


Guest


Thank you, Andrei.
Posted 19 Jul, 2013 13:11:25 Top