Vadim Usmanov
Guest
|
Hi.
I'm trying to fill in a field on a web page searching for tab url .
This code works well.
Dim MyField
Dim i
For i = 0 To GetModuleCount() - 1
Dim MyModule As IEModule = TryCast(Me.GetModuleByTabIndex(i), IEModule)
If MyModule IsNot Nothing Then
Dim TabDomain = MyModule.HTMLDocumentObj.domain
If TabDomain = "translate.google.ru" Then
MyField = MyModule.HTMLDocumentObj.getElementById("source")
If (MyField IsNot Nothing) Then
MyField.Value = "Test"
End If
MyModule.TabActivate()
Exit Sub
End If
End If
Next
But sometimes when I close and open a new tab(s) an exception throws in the line with MyModule.HTMLDocumentObj.domain:
Exception Type: System.NullReferenceException
Exception Message: Object reference not set to an instance of an object.
or
Exception Type: System.NotSupportedException
Exception Message: Exception HRESULT: 0x800A01B6 |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Vadim,
Please try the code below:
Public Function GetDomain() As String
If Not (HTMLDocumentObj Is Nothing) Then
Return HTMLDocumentObj.domain
End If
Return String.Empty
End Function
Public Function GetElement(id As String) As Object
If Not (HTMLDocumentObj Is Nothing) Then
Return HTMLDocumentObj.getElementById(id)
End If
Return String.Empty
End Function
Dim MyField
Dim i
For i = 0 To GetModuleCount() - 1
Dim MyModule As IEModule = TryCast(Me.GetModuleByTabIndex(i), IEModule)
If MyModule IsNot Nothing Then
Dim TabDomain = MyModule.GetDomain()
If TabDomain = "translate.google.ru" Then
MyField = MyModule.GetElement("source")
If (MyField IsNot Nothing) Then
MyField.Value = "Test"
End If
MyModule.TabActivate()
Exit Sub
End If
End If
Next
|
|
Vadim Usmanov
Guest
|
Thank you Sergey. But unfortunately the problem is not solved... |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Vadim,
What the error do you get now? Please use the Visual Studio Debugger to learn what the code produces the error. Also, you need to check the value of the Me.IEApp.ReadyState property before you obtain the domain. It should be 'Interop.SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE'. |
|
Vadim Usmanov
Guest
|
Thanks Sergey. I'll check. |
|