2

Website: http://www.cookcountypropertyinfo.com/default.aspx. I wanted to automate the process of inputting values in 'BY PIN' section and then submit 'Search' button. Below mentioned code fills into 'BY PIN' section but it fails the validation criteria and returning error message. However, manually inputting same value returning result. I am unable to figure out what is missing in my code.

Private Sub Command443_Click()
Dim PINArray() As String
PINArray() = Split(PINText, "-")


Set objie = CreateObject("InternetExplorer.Application")
WebSite = "http://www.cookcountypropertyinfo.com/default.aspx"
DoCmd.Hourglass True
With objie
.Visible = False
.navigate WebSite
Do While .Busy Or .ReadyState <> 4
DoEvents
Loop
.Visible = True
Set element = .Document.getElementsByName("ctl00$ContentPlaceHolder1$PINAddressSearch$pinBox1")
element.Item(0).Value = PINArray(0)
element.Item(0).fireevent "onkeyup"

Set element = .Document.getElementsByName("ctl00$ContentPlaceHolder1$PINAddressSearch$pinBox2")
element.Item(0).Value = PINArray(1)
element.Item(0).fireevent "onkeyup"

Set element = .Document.getElementsByName("ctl00$ContentPlaceHolder1$PINAddressSearch$pinBox3")
element.Item(0).Value = PINArray(2)
element.Item(0).fireevent "onkeyup"


Set element = .Document.getElementsByName("ctl00$ContentPlaceHolder1$PINAddressSearch$pinBox4")
element.Item(0).Value = PINArray(3)
element.Item(0).fireevent "onkeyup"


Set element = .Document.getElementsByName("ctl00$ContentPlaceHolder1$PINAddressSearch$pinBox5")
element.Item(0).Value = PINArray(4)
element.Item(0).fireevent "onkeyup"
element.Item(0).fireevent "onkeydown"

Set element = .Document.getElementsByName("ctl00$ContentPlaceHolder1$PINAddressSearch$btnSearch")
element.Item(0).Click

End Sub
Erik A
  • 31,639
  • 12
  • 42
  • 67
Sonu Kumar
  • 108
  • 6

1 Answers1

0

The search button on the page invoke 'ValidateSearch' function; ValidateSearch:

function ValidateSearch() {
    var searchToValidate = $('#searchToValidate').val();
    $('#__EVENTARGUMENT').val('btn' + searchToValidate);
    $('#invalidpinaddressmessage').hide();

    if (searchToValidate == "PIN") {
        if (typeof (Page_ClientValidate) == 'function') {
            Page_ClientValidate('pin');
        }
    }
    else if (searchToValidate == "Address") {
        if (typeof (Page_ClientValidate) == 'function') {
            Page_ClientValidate('address');
        }
    }
    else if (searchToValidate == "") {
        $('#invalidpinaddressmessage').show();
        return false;
    }

    if (Page_IsValid) {
        return true;
    }
    else {
        scrollToValidation(60);
        return false;
    }
}

the $('#searchToValidate').val() refers to below mentioned HTML hidden tag

<input type="hidden" 
name="ctl00$ContentPlaceHolder1$PINAddressSearch$searchToValidate" 
id="searchToValidate" />

In my vba code, I inserted the value of input tag 'searchToValidate' to 'PIN' to bypass and submit the search button.

.Document.getElementById("searchToValidate").Value = "PIN"
Set element =.Document.getElementsByName("ctl00$ContentPlaceHolder1$PINAddressSearch$btnSearch")
element.Item(0).Click
Sonu Kumar
  • 108
  • 6