I am having trouble getting my Sub to pull in the HTML of a new tab opened using .click within the routine. It pulls open the first instance of IE, just fine. It then searches the links on that page for a particular string, and clicks the link, when the string is found. Next, I need it to search the HTML of the new tab for a div with a particular class name, and pull the text from the div. The HTML pulled with .innerHTML appears incomplete. Furthermore, I examine the HTML in a MsgBox for the first page, and, what I expect to be the second tab, and the results are the same. The code is here
There are a lot of lines commented out, but also actual comments describing what the code should do. Any assistance is Greatly Appreciated.
Code:
Private Sub PrcButton_Click() 'Define IE as an Visible Internet Explorer Window, Item as a string (part number) to be searched on website
Dim IE As New InternetExplorer
IE.Visible = True
Dim Price As String
'Price = ""
'Dim A As Range: Set A = Sheets("Sheet1").Range("A3:A2000")
Dim Item As String
'For Each Item In A:
'Set Item as a particular part number, Navigate to the Search Results on the page for Item
Item = "1300RE-24"
IE.navigate "http://www.wholesalesolar.com/search?cx=016891376637286370789%3A57yxrli0cuq&cof=FORID%3A11%3BNB%3A1&ie=UTF-8&q=" & Item & "&sa=Search"
'Loop until the page is loaded
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
'Search links on page for exact part number and click the link with the exact match
Set Links = IE.document
For Each link In Links.Links
If InStr(link.innerText, Item) > 0 Then
link.Click
Exit For
End If
Next
'Loop until the page is loaded
Do While IE.readyState <> READYSTATE_COMPLETE
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Loop
'Add time for page to load
'T1 = Now
'Do While (Now < T1 + TimeValue("0:00:40"))
'DoEvents
'Loop
'Reset Links to the new page-----------THIS IS WHERE I AM HAVING TROUBLE------------
Set Links = IE.document
'FOR EXAMINING NEW PAGE HTML
'Links_HTML = Links.body.innerHTML
'Search HTML from new page for price
For Each item_blck In Links.getElementsByClassName("product-row")
item_HTML = item_blck.document.innerHTML
item_price = item_HTML.getElementsByClassName("price")(0).innerText
Next
'Show what you find
MsgBox item_HTML
'-------ALWAYS SHOWS BLANK. I THINK IT IS LOOKING AT HTML FROM ORIGINAL PAGE---------
'item_test = item_HTML.innerHTML
'If InStr(Page_HTML, "cart") > 0 Then
'Page_HTML = Mid(Page_HTML, InStr(Page_HTML, "price"), Len(Page_HTML))
'Dim item_price As String
'item_price = Mid(Page_HTML, 1, InStr(Page_HTML, "</div>=="))
'Price = CDbl(item_price)
'End If
'Sheets(Sheet1).Range(F4).Value = item_price
'Next Item
End Sub
There are a lot of lines commented out, but also actual comments describing what the code should do. Any assistance is Greatly Appreciated.