gpt4 book ai didi

excel - 获取传递给网站表单的数据

转载 作者:行者123 更新时间:2023-12-04 22:31:01 25 4
gpt4 key购买 nike

我正在尝试将数据传递到第四页上的表单中。我已经成功地浏览了登录我的宏,根据输入的数据搜索特定页面,转到该特定页面,然后将我想要在其中输入数据的表单拉到多个位置。

Sub Test()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://mywebsite.com/Pages/MainSite/Default.aspx"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
IE.document.getElementById("txtUserName").Value = "dummyusername"
IE.document.getElementById("txtPassword").Value = "password"
IE.document.getElementById("btnLogin").Click
End Sub

Sub Next2()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "mywebsite.com/pages/hr/TimeEntryDashboard.aspx"
Do While IE.Busy
Application.Wait DateAdd("s", 2, Now)
Loop
IE.document.getElementById("MainContent_MainContent_txtStartDateFilter").Value = "10/13/2018"
IE.document.getElementById("MainContent_MainContent_txtEmployeeNameFilter").Value = "122631"
IE.document.getElementById("MainContent_MainContent_btnFind").Click
End Sub

Sub Next3()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "mywebsite.com/pages/hr/TimeAndInspectionWizard.aspx?id=0245b750-4cde-47da-a754-fb7f8bfecfc9"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
IE.document.getElementById("imgGridTimeDetailsArrow0").Click
IE.document.getElementById("MainContent_MainContent_tcMain_tpValidation_rptInspectionDetails_imbGridInspectionDetailsOptionsAdd_0").Click
End Sub

Sub Next4()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
' IE.Visible = True
' IE.Navigate "mywebsite.com/pages/hr/TimeAndInspectionWizard.aspx?id=0245b750-4cde-47da-a754-fb7f8bfecfc9"
Do While IE.Busy
Application.Wait DateAdd("s", 2, Now)
Loop
IE.document.getElementById("MainContent_MainContent_tcMain_tpInspectionDetails_txtInspectionDetailsLotNumber").Value = "12345"
IE.document.getElementById("MainContent_MainContent_tcMain_tpInspectionDetails_txtInspectionInspectedQuantity").Value = "1"
IE.document.getElementById("MainContent_MainContent_tcMain_tpInspectionDetails_txtGoodWithoutReworkQuantity").Value = "1"
IE.document.getElementById("MainContent_MainContent_tcMain_tpInspectionDetails_txtAddInspectionResult").Click
End Sub

上面的这部分在应该在屏幕上输入数据的第一部分产生错误。

最佳答案

作为代码验证的一部分,您必须检查元素是否存在,这也将引导您以更好的方式识别问题。例如,这是用验证重写的代码。

Sub Next4()
Dim IE As Object, Elem As Object
Set IE = CreateObject("InternetExplorer.Application")

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

With .document

Set Elem = .GetElementById("MainContent_MainContent_tcMain_tpInspectionDetails_txtInspectionDetailsLotNumber")
If Not Elem is nothing Then
Elem.Value = "12345"
Set Elem = Nothing
End If

Set Elem = .GetElementById("MainContent_MainContent_tcMain_tpInspectionDetails_txtInspectionInspectedQuantity")
If Not Elem is nothing Then
Elem.Value = "1"
Set Elem = Nothing
End If

Set Elem = .GetElementById("MainContent_MainContent_tcMain_tpInspectionDetails_txtGoodWithoutReworkQuantity")
If Not Elem is nothing Then
Elem.Value = "1"
Set Elem = Nothing
End If

Set Elem = .GetElementById("MainContent_MainContent_tcMain_tpInspectionDetails_txtAddInspectionResult")
If Not Elem is nothing Then
Elem.Click
Else
MsgBox "Can't Click as Element Missing : " & "MainContent_MainContent_tcMain_tpInspectionDetails_txtAddInspectionResult"
End If
End With
End With
End Sub

关于excel - 获取传递给网站表单的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52826135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com