首页 > 解决方案 > 尝试使用 IE 和 excel vba 在 sap webapp 上自动输入数据

问题描述

我可以登录,但是我无法从那里选择任何选项。

尝试阅读 UI 自动化但无法遵循,有人可以帮助编写点击代码

Dim IE As Object
Dim doc As HTMLDocument

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

IE.navigate "https://website.com/"

Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

Set doc = IE.document

IE.document.getElementById("j_username").Value = "user"
doc.getElementById("j_password").Value = "pass"
doc.getElementById("logOnFormSubmit").Click

Do While IE.Busy
Application.Wait DateAdd("s", 10, Now)
Loop

Dim NewTicketBtn As Object
Set NewTicketBtn = doc.getElementById("__tile0-__component0---landingDetail--aboPanel-2")
NewTicketBtn.Click

标签: excelvbainternet-explorerui-automation

解决方案


尝试这个。阅读我在宏中的评论:

Sub test()

  Dim IE As Object
  Dim doc As HTMLDocument
  Dim NewTicketBtn As Object

  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  IE.navigate "https://website.com/"
  Do While IE.Busy: DoEvents:  Loop

  Set doc = IE.document

  doc.getElementById("j_username").Value = "user"
  doc.getElementById("j_password").Value = "pass"
  doc.getElementById("logOnFormSubmit").Click

  'This don't work here because the ready state of the IE is allready 'complete'
  'Do While IE.Busy
  'Application.Wait DateAdd("s", 10, Now)
  'Loop
  '
  'You must set a manual break for a few seconds to load the page after the login
  'If 3 seconds not enough go higher
  Application.Wait (Now + TimeValue("0:00:03"))

  'Here you can't work anymore with 'doc' because the document in the IE has changed
  Set NewTicketBtn = IE.document.getElementById("__tile0-__component0---landingDetail--aboPanel-2")
  NewTicketBtn.Click
End Sub

推荐阅读