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
|
|
SilverStr
Posts: 28
Joined: 2013-03-31
|
Why not hook DocumentComplete2, wait until rootDocLoaded is true and then conduct the call to getElementById? |
|
Andrei Smolin
Posts: 18543
Joined: 2006-05-11
|
Thank you SilverStr!
Hello Vadim,
Does the solution suggested by SilverStr suits you?
Andrei Smolin
Add-in Express Team Leader |
|
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
|
|
Andrei Smolin
Posts: 18543
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 |
|