Reputation: 22440
For the last few hours I've been trying to fix a simple issue but can't figure out where I'm going wrong. There is a webpage in which there are two srarch boxes
to be filled in to populate the result; one for street number
and the other for street name
. The two search terms are already set within the .SendKeys
in my below script so that you can run it as it is.
There are three iframes
to deal with to reach the content. First iframe
appears in the landing page in which the search boxes
are. I've switched it. However, the last two nested iframes
appear in the result page. I've switched the first one (from the result page) but can't switch the last one to reach the content I'm looking for. I'm trying to extract VANDREUMEL SILVIA HERNANDEZ
this name under the table captioned with the header Ownership History
.
When it comes to switch the second iframe
(named as quickframe
which is the id
), it throws an error element not found error
. How can I solve this problem in order to get the owner name
?
Once again, search terms are:
street no.
which should be10023
street name
which should beHARDISON LN
Then hit the search button to populate the results.
This is my attempt so far:
Sub CollectInformation()
Dim post As Object
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)
.SwitchToFrame .FindElementById("quickframe", Timeout:=10000) ''error thrown here
For Each post In .FindElementsByCss("th", Timeout:=7000)
If InStr(1, post.Text, "VANDREUMEL", 1) > 0 Then R = R + 1: Cells(R, 1) = post.Text: Exit For
Next post
Stop
End With
End Sub
Btw, If you manually try the link to see the search boxes
then you need to click on search by address
in order for that search boxes
to show up.
Upvotes: 2
Views: 125
Reputation: 22440
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 If
End Sub
Reference to add to the library:
Microsoft HTML Object Library
Microsoft WinHTTP Services, version 5.1
Output:
Upvotes: 1
Reputation: 84465
You are in the right frame already
Option Explicit
Public 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 With
End Sub
Output for just the name:
Output for header:
That th
tag contains the name and address
Upvotes: 2