为了账号安全,请及时绑定邮箱和手机立即绑定

如何让 VBA 提交 javascript 表单?

如何让 VBA 提交 javascript 表单?

白猪掌柜的 2021-06-29 04:45:28
我不确定我是否正确引用了按钮。我不断得到:运行时错误“438”:对象不支持此属性或方法。这是我的代码目前的样子:Sub russInd()    Dim oButton As Object, HTMLdoc As Object    Dim sht1 As Worksheet, myURL As String    Set ie = CreateObject("InternetExplorer.Application")        Set sht1 = Worksheets("Day 1")        myURL = sht1.Cells(32, 2).Value        ie.navigate myURL        ie.Visible = True        Do Until ie.ReadyState = 4            DoEvents        Loop        'Locate The correct forms and buttons        Set HTMLdoc = ie.document        Set oButton = HTMLdoc.querySelectorAll("a[href='javascript:submitForm(document.forms[0].action);']")        'Check All Checkboxes        HTMLdoc.getElementByID("chkAll").Click        oButton.ClickEnd Sub我使用的网页是:  https://indexcalculator.ftserussell.com/下面是网页代码:我需要单击下一个按钮,我确实尝试使用.getElementByID("CtlNavigation_lblControl")要单击按钮,但是只是跳过了命令,我猜它什么也没单击。谢谢!
查看完整描述

3 回答

?
繁星点点滴滴

TA贡献1803条经验 获得超3个赞

将您的选择器设置为:(意思是在父A元素中查找任何图像。)


Set oButton = HTMLdoc.querySelectorAll("a > img")

这是修改后的完整代码:


Sub russInd()

    Dim oButton As Object, HTMLdoc As Object

    Dim sht1 As Worksheet, myURL As String

    Set ie = CreateObject("InternetExplorer.Application")

        Set sht1 = Worksheets("Day 1")

        myURL = sht1.Cells(32, 2).Value

        ie.navigate myURL

        ie.Visible = True


        Do Until ie.ReadyState = 4

            DoEvents

        Loop


        'Locate The correct forms and buttons

        Set HTMLdoc = ie.document

        Set oButton = HTMLdoc.querySelectorAll("a > img")

        'Check All Checkboxes

        HTMLdoc.getElementByID("chkAll").Click

        oButton.Click

End Sub


查看完整回答
反对 回复 2021-07-01
  • 3 回答
  • 0 关注
  • 192 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号