The title might be confusing, but it's not just an impression. I had a previous post about this but the core problem is actually deeper than this.
Basically I have a big code in which I navigate to an intranet webpage from my company ( let's call this webpage the Start webpage).
I then provide username and password information and click on the "login" button. Clicking on the login button will create a new webpage in a NEW window. We will call this new webpage the Main webpage.
The Main webpage contains all the important information I want to get while the Start webpage is now useless to me.
First challenge here was then to "activate" or "select" the Main webpage since the Start webpage was still activated. The Main webpage has obviously a URL but it's impossible to directly navigate to it, so that's why I talk about "activation" or "selection" of the webpage. I managed to do this with the help of that forum's post
If you have any questions about it let me know, but it's not the problem of this post.
So with the Main webpage activated, I want to click on an element to display more information. This element is embedded in the frame postfachcontent. See Main Page HTML document Overview and Zoom on part to click on.
In my previous post mentioned above, I tried to do this but got familiar with "embedded" elements who made the task harder.
With the help of other members, I figured out there could be 2 ways to get in the postfachcontent frame :
By selecting child by child the frames :
Set w = IEWindowFromLocation(path) Dim IEDoc As HTMLDocument Set IEDoc = w.document ' w is the so called Main webpage that I selected peviously in the code Dim SubFramesCollection As HTMLWindow2 Dim GoodFrame As HTMLWindow2 Dim Postfachcontent_Frame As HTMLWindow2 Set SubFramesCollection = IEDoc.frames ' the length of this is 3 since it contains the 3 main frames Set GoodFrame = SubFramesCollection(1).frames ' this contains the 2 frames of the "contentframe" frame so length = 2 Set Postfachcontent_Frame = GoodFrame(1) Doc2 = Postfachcontent_Frame.document
But the problem here is that once I accessed to the frame I got confused on how to actually select the element of the table and click on it
- By "navigating" to a new webpage which would be a reduced version of the Main webpage only focusing on the frame I am interested in so navigating to Main Webpage URL & contentframe.src (or postfachcontent.src).
But the problem here, as I said above, is that I can't navigate to the Main webpage directly so I thought I could try to declare a New InternetExplorer window and give it a location without actually navigating to the page ( but it doesn't work unfortunately). Attempt below :
Set w = IEWindowFromLocation(path)
Dim IEDoc As HTMLDocument
Dim IEDok As HTMLDocument
Set IEDoc = w.document
Dim ContentFramesCollection As IHTMLElementCollection
Dim ContentFrame As HTMLFrameElement
Dim PostFachContentFramesCollection As IHTMLElementCollection
Set ContentFramesCollection = IEDoc.getElementsByName("contentframe") ' this works and returns 1 item which is the frame called contentframe, so it s a collection of element containing 1 element only
' MsgBox ContentFramesCollection.Length ' returns 1
If Not ContentFramesCollection Is Nothing Then
Set ContentFrame = ContentFramesCollection(0) ' Here we isolate the unique item contained in MainFramesCollection and store it in a single element called ContentFrame
MsgBox w.document.Location & ContentFrame.src
'On Error Resume Next
Set w2.document.Location = w.document.Location & ContentFrame.src
'MsgBox Err.Description ' returns automation error unspecified error
Set IEDok = w2.document
Set PostFachContentFramesCollection = IEDok.getElementsByName("postfachcontent")
MsgBox PostFachContentFramesCollection.Length ' returns 0...oops
End If
Thanks for reaching that line and any help is welcome !
SOLUTION : For those it might interest, I found with the help of dee and the asnwer of Tim Williams on here a way to click on one of the multiple possible elements containing a "onclick" property.
For the greedy ones, here's the straight in-one-line solution which lists the clickable elements :
where IEDoc is the HTML document of the Main webpage.
Remarks :
In order to get this final solution, I had to do some tests to see which type I was dealing with to make sure I knew what I was doing. You can see these tests steps in the following code sample as well as their displayed result in the MsgBox in comment :
Here my idea in code (this code is untested). First navigate to start page to login. Then find the main page. From the main page navigate to first frame and then to second. After that the dom element should contain the target button which can be now clicked. HTH