Cannot Write In Inputbox Inside A Frame Of A Website
this post is the following of Filling Internet Explorer inputbox We tried to isolate the problem and it seems that I'm not able (maybe due to a JavaScript in the page? - Please tak
Solution 1:
The problem you have is that when your target input box 'Nachnamevalue' is inside of an IFrame
then IE has to navigate to target page first and then to the IFrame as well.
If no navigation to the IFrame
occures, then the DOM does not contain elements which are inside of IFrame
and that is why it was not working. HTH
(The sample code uses files which are located on my PC, so replace the url with your actual url from intranet and the name of the 'main.html' with the name of actual page.)
Option Explicit
' Add reference to Microsoft Internet Controls (SHDocVw)
'Add reference to Microsoft HTML Object Library
Sub AddInfoFromIntranet()
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim url As String
' Navigate to main page first
url = "file:///c:/temp/Noldor/"
Set ie = New SHDocVw.InternetExplorer
ie.Visible = True
ie.navigate url & "main.html"
While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Dim inputs As MSHTML.IHTMLElementCollection
Dim iFrames As MSHTML.IHTMLElementCollection
Dim iFrame As MSHTML.HTMLFrameElement
'Get top_window frame and navigate to it thenSet doc = ie.document
Set iFrames = doc.getElementsByName("top_window")
If Not iFrames Is Nothing ThenSet iFrame = iFrames(0)
ie.navigate url & iFrame.src
While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set inputs = doc.getElementsByName("Nachnamevalue")
If Not inputs Is Nothing Then
inputs(0).Value= "Test123"
End If
End If
ie.Quit
Set ie = Nothing
End Sub
Sample HTML of main.html
:
<html><head><title></title></head><framesetcols=""rows=""><framename="top_window"src="top_window.html" /></frameset><noframes><!-- no frames content here --></noframes></html>
Sample HTML of top_window.html
:
<html><head><title></title></head><bodybgcolor="#ffffcc"><formname="Suchform"action="index.cfm">
Nachname:
<inputname="Nachnamevalue"type="text"size="8"></form></body></html>
Post a Comment for "Cannot Write In Inputbox Inside A Frame Of A Website"