0

I would like to have the possibility to autofill the box on the website and validating it (Click OK) straight from the VBA code. I've inspected the website and the situation looks pretty much like this:

enter image description here

The following code:

Sub WBPoor()
Dim IE As Object
Dim classElement As Object
    
Set IE = CreateObject("InternetExplorer.Application")
With IE
    .Visible = True
    .navigate "https://www.openpoor.com"        'CHANGE URL
    While .Busy Or .readyState <> 4: DoEvents: Wend
End With

Set classElement = IE.document.getElementsByClassName("searchbox")(0).getElementsByTagName("input")    'CHANGE CLASS NAME
If Not classElement Is Nothing Then
    ActiveSheet.Range("A1").Value = "yes"
    SendKeys "CB1 3QQ", True
Else
    ActiveSheet.Range("A1").Value = "no"
End If
End Sub

returns the Yes value but nothing happens to the website.

How could be possible to type postcode and validate it?

braX
  • 11,506
  • 5
  • 20
  • 33
Geographos
  • 827
  • 2
  • 23
  • 57
  • Using IE is a bad idea because MS is actively phasing it out. `SendKeys` always sends to the currently active application and within it to the element with the focus. So you send somewhere, but certainly not to the input tag. `SendKeys` is also not necessary. – Zwenn Mar 16 '23 at 12:51
  • The input tag has the `value` property for its content. However, you have not yet addressed any specific input tag, but only created a node collection of all input tags. Even if there is only one, it is in a collection. With your existing code, you can address it like this if it is the first input tag in the html code `classElement(0).value("CB1 3QQ")` If there is no input tag, there is still an ampty collection and you get an object error. I don't call the URL because my virus scanner doesn't like it. – Zwenn Mar 16 '23 at 12:54
  • Zwenn, I know, that IE is a bad idea, but as far as I know, there is no VBA support for MS Edge yet, that's why I had to stay with IE. – Geographos Mar 16 '23 at 13:59
  • You can try this for automating Edge. (I didn't try it by myself) https://stackoverflow.com/questions/70619305/automating-edge-browser-using-vba-without-downloading-selenium Or you can use Seleniumbasic. https://stackoverflow.com/questions/69118936/vba-script-to-convert-from-internet-explorer-to-edge-or-chrome-browser – Zwenn Mar 16 '23 at 20:26
  • @Zwenn where roughly should I place the classElement(0)? I am quite lost here with your hint. – Geographos Mar 20 '23 at 12:16
  • Replace this line `SendKeys "CB1 3QQ", True` by this `classElement(0).value("CB1 3QQ")`. This only works if it really is an input tag and it is the first one in the collection. – Zwenn Mar 20 '23 at 16:05
  • It was... Value = "CB1 3QQ" but it works! Thanks! Do you know how to validate it? (Click OK) from the VBA Excel macro? – Geographos Mar 21 '23 at 09:20
  • Oh yes, you are right. You can click the button with the following line of code. Place it after the line we spoke about. `IE.document.getElementsByClassName("searchcontainer")(0).getElementsByTagName("button")(0).click` – Zwenn Mar 22 '23 at 01:10
  • Object doesn't support this property or method - this is what I get already. – Geographos Apr 14 '23 at 14:28
  • I have created the code line based on your screenshots. If it doesn't work, I can't say anything more about it. You didn't give the real url and I'm not a visionary. – Zwenn Apr 14 '23 at 21:41

0 Answers0