PDA

View Full Version : VBA Interacting With A Child Window



Vicman
03-03-2016, 03:17 PM
I'm working on my first web scraper. Basically I need to scrape from a parent page and a child page. The parent page has a list of items (names and product #, etc). I can scrape this general information from the parent page without problems. But, I also need to scrape the details of each item. To do this I need to click on each item and set the focus on the child window that pops up with the detail information. However, I can't get the program to change focus from the parent page to the child window so that I can scrape the details for the item clicked. It's very frustrating. How do I get my [/FONT]VBA[COLOR=#222426][FONT=Arial] code to change from the parent's page collection to the child's collection?


Dim ie As InternetExplorer
Dim Document As HTMLDocument
Dim ele As Object, myURL as String
Dim Document As HTMLDocument
Dim AllLinks As IHTMLElementCollection

Set ie = New InternetExplorer
myURL = Range("Website").Value ‘URL is set in a named range on the spreadsheet
ie.navigate (myURL)
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop

For Each ele In ie.Document.all
Set AllLinks = ie.Document.getElementsByTagName("a")
For Each Hyperlink In AllLinks
‘There are several frames, so only open the one where criteria is met
If InStr(Hyperlink.href, "Product1234") And InStr(Hyperlink.innerText, "Details") Then
‘Opens child window
Hyperlink.Click
‘NEED CODE HERE TO INTERACT WITH CHILD FRAME WINDOW THEN GO BACK TO PARENT WINDOW
End if
Next Hyperlink
Next ele

Thanks for the help.