getelementbyid 通过 msexcel vba 对象需要 424

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17040530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:35:10  来源:igfitidea点击:

getelementbyid via msexcel vba object required 424

vbaexcel-2010getelementbyid

提问by user2473828

I have been struggling to get the getelementbyid (or name) code working. What I want to do is submit login details without using sendkeys. Probably is just a matter of not understanding the website. I can view the element by

我一直在努力使 getelementbyid(或名称)代码正常工作。我想要做的是在不使用 sendkeys 的情况下提交登录详细信息。可能只是不了解网站的问题。我可以通过以下方式查看元素

MsgBox (Mid(ObjIE.Document.frames(1).Document.body.outerHTML, 1800, 1000))

MsgBox (Mid(ObjIE.Document.frames(1).Document.body.outerHTML, 1800, 1000))

which shows id= userName and name = userName. But when I try to getelementbyid it comes up with an object required error, as if its not there.

其中显示 id= userName 和 name = userName。但是当我尝试 getelementbyid 时,它出现了一个需要对象的错误,就好像它不存在一样。

采纳答案by Santosh

Here you go

干得好

Instead of this URL http://fieldwork.genesisenergy.co.nz/

而不是这个网址http://fieldwork.genesisenergy.co.nz/

I am directly navigating to below frame src

我直接导航到下面的框架 src

<frame name="Login" src="LoginGenesis.aspx?bgColor=FFFFFF&trimColor=FF6600" frameBorder="0" marginWidth="0" marginHeight="0" scrolling="auto">



  Sub Website()

    Dim IE As Object, Doc As Object, UserName As Object, Password As Object, strCode As String


    Set IE = CreateObject("internetexplorer.application")
    IE.Visible = True
   ' IE.navigate "http://fieldwork.genesisenergy.co.nz/"

      IE.navigate "http://fieldwork.genesisenergy.co.nz/LoginGenesis.aspx?bgColor=FFFFFF&trimColor=FF6600"

        Do While IE.readystate <> 4: DoEvents: Loop

        Set Doc = CreateObject("htmlfile")
        Set Doc = IE.document

        Set UserName = Doc.getelementbyid("userName")
        UserName.Value = "santosh"


        Set Password = Doc.getelementbyid("userPassword")
        Password.Value = "santosh@123"


       Set btnLogin = Doc.getelementbyid("loginUser")
        btnLogin.Click
End Sub