Нажмите кнопку в IE, используя VBA - PullRequest
0 голосов
/ 22 мая 2018

Я пытаюсь автоматизировать загрузку с веб-страницы, и для этого требуется, чтобы я нажал кнопку для доступа к форме входа.

Я несколько раз искал ответы в Интернете и в различных темах, но теперь получаю сообщение об ошибке:

'Объект не поддерживает это свойство или метод'.

HTML-часть кнопки, которую я хочу нажать:

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

Есть предложения?

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

Ответы [ 2 ]

0 голосов
/ 22 мая 2018

Или используйте селектор запросов CSS

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
0 голосов
/ 22 мая 2018

Ссылка, которую вы указали, содержит указанную вами кнопку, но значение другое.

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

Есть несколько способов нажать эту кнопку.Самый простой способ, который я вижу в вашей конкретной ситуации, - нажать третью кнопку.На веб-сайте есть 3 кнопки, и вы можете сделать следующее:

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

Массив кнопок начинается с 0, поэтому 2 - третья кнопка.


Другой способ сделатьэто, чтобы зациклить все кнопки и найти ту, которую вы хотите:

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...