我一直在努力让getelementbyid(或名称)代码正常工作。我想要做的是提交登录详细信息而不使用sendkeys。可能只是不了解网站的问题。我可以通过
查看元素MsgBox(Mid(ObjIE.Document.frames(1).Document.body.outerHTML,1800,1000))
显示id = userName和name = userName。但是当我尝试getelementbyid时,它会出现一个对象需要的错误,好像它不在那里。
答案 0 :(得分:0)
你去吧
而不是此网址http://fieldwork.genesisenergy.co.nz/
我直接导航到frame 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