Unable to reach the content stored within iframes Unable to reach the content stored within iframes selenium selenium

Unable to reach the content stored within iframes


You are in the right frame already

Option ExplicitPublic Sub CollectInformation()    With New ChromeDriver        .get "http://hcad.org/quick-search/"        .SwitchToFrame .FindElementByTag("iframe", timeout:=7000)        .FindElementById("s_addr", timeout:=7000).Click        .FindElementByCss("input[name='stnum']", timeout:=7000).SendKeys "10023"        .FindElementByCss("input[name='stname']", timeout:=7000).SendKeys "HARDISON LN"        .FindElementByCss("input[value='Search']", timeout:=10000).Click        .SwitchToFrame .FindElementByCss("iframe", timeout:=7000)        Debug.Print .FindElementByCss("input[name=searchval]", timeout:=7000).Attribute("value")  '<== Just the name        ' Debug.Print .FindElementByCss("tbody th:nth-child(2)", timeout:=7000).Text  '<== Header i.e. Name and address    End WithEnd Sub

Output for just the name:

CSS selector

name only


Output for header:

That th tag contains the name and address

css query

Output


Although the problem has already been resolved, I decided to come up with a robust solution. If you follow the way I tried below, you no longer worry about the iframes. All you need to do is send POST request using the proper headers along with the appropriate ActiveX in which you will get cookie support. However, Microsoft WinHTTP Services is the right candidate for you to achieve the same.

This is how you can go:

Sub CollectInformation()    Dim Http As New WinHttp.WinHttpRequest, Html As New HTMLDocument    Dim oelem As Object    With Http        .Open "POST", "https://public.hcad.org/records/QuickSearch.asp", False        .setRequestHeader "Content-type", "application/x-www-form-urlencoded"        .setRequestHeader "User-Agent", "Mozilla/5.0"        .send "search=addr"    End With    With Http        .Open "POST", "https://public.hcad.org/records/QuickRecord.asp", False        .setRequestHeader "Content-type", "application/x-www-form-urlencoded"        .setRequestHeader "User-Agent", "Mozilla/5.0"        .setRequestHeader "Referer", "https://public.hcad.org/records/QuickSearch.asp"        .send "TaxYear=2018&stnum=10023&stname=HARDISON+LN"        Html.body.innerHTML = .responseText    End With        Set oelem = Html.querySelector("input[name=searchval]")    If Not oelem Is Nothing Then        MsgBox oelem.getAttribute("value")    End IfEnd Sub

Reference to add to the library:

Microsoft HTML Object LibraryMicrosoft WinHTTP Services, version 5.1

Output:

enter image description here