0

I am trying to automate a download from a webpage, and it requires that i klik a button to access a login form.

I have searched the web and various threads for answers, with some luck, but now I get the error:

'Object doesnt support this property or method'.

The HTML part for the button i want to click is:

<button name="idpEndpointId" type="submit" value="https://saml.nemlog-in.dk"   class="btn btn-primary">Vælg</button>

Any suggestions?

Private Sub download()

Dim IE As Object
Dim document As Object
Dim nemKnap As Object

'Create IE object
Set IE = CreateObject("InternetExplorer.Application")

'Show browser
IE.Visible = True

'Navigate to URL
IE.Navigate "https://link.com/"

'Statusbar if waittime
Application.StatusBar = "Page is loading."

'Wait
'Application.Wait Now + TimeValue("00:00:02")

' First attempt on tabbing through the website to press enter
  '  SendKeys "{TAB}"
  '  SendKeys "{TAB}"
  '  SendKeys "{TAB}"
  '  SendKeys "{TAB}"
  '  SendKeys "{TAB}"
  '  SendKeys "{TAB}"
  '  SendKeys "{TAB}"

'Do
'Loop While IE.busy

Do
Loop Until IE.readystate = 3
Do
Loop Until IE.readystate = 4

Set nemKnap = IE.document.getElementsByValue("https://saml.nemlog-in.dk")

'nemKnap.Click // is supposed to happen afterwards

End Sub
6
  • Is the button in a form? If so, try to grab the form and then submit the form. Commented May 22, 2018 at 9:36
  • No, its not in a form. But it has the same name, type and class as two other buttons - thats why i chose the getElementsByValue. Commented May 22, 2018 at 10:17
  • 1
    Is this an internal url or can it be shared? Commented May 22, 2018 at 10:41
  • OK, the type="submit" made me think it was in a web form. Does the button name change? have you tried getElementByID? Commented May 22, 2018 at 11:00
  • This is the link: kommune.bbr.dk. I could be wrong about it being a form? Have not tried getElementByID - having a hard time finding the ID on the page...? Commented May 22, 2018 at 12:02

2 Answers 2

2

The link you provided has the button you mentioned but the value is different.

<button name="idpEndpointId" type="submit" value="https://saml.adgangsstyring.stoettesystemerne.dk" class="btn btn-primary">Vælg</button>

There are a few ways to click this button. The easiest way I see for your specific situation is to click the 3rd button. The website has 3 buttons and you can do the following:

IE.document.getElementsByTagName("button")(2).Click

The array of buttons starts at 0, that's why 2 is the 3rd button.


Another way to do this, is to loop all the buttons and find the one you want:

Set allButtons = IE.document.getElementsByTagName("button")
Do While i < allButtons.Length
    If allButtons(i).Type = "submit" And allButtons(i).Value = "https://saml.adgangsstyring.stoettesystemerne.dk" Then
        allButtons(i).Click
        Exit Do
    End If
    i = i + 1
Loop
Sign up to request clarification or add additional context in comments.

Comments

1

Or use CSS queryselector

Option Explicit

Public Sub ClickButton()

    Dim IE As New InternetExplorer, html As HTMLDocument

    With IE
        .Visible = True
        .navigate "https://kommune.bbr.dk/IdPSelection#!/"
        While .Busy = True Or .readyState < 4: DoEvents: Wend
        Set html = .document
    End With

   html.querySelector("button.btn.btn-primary[value=""https://saml.nemlog-in.dk""]").Click

   Stop   '<== delete this line later. This is just to enable you to observe result.
   '<Other code>
   .Quit

End Sub

1 Comment

Any feedback on this please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.