Q1)如何在此网页上输入密码和用户名" https://.com/1/19/login.esp" ?
我已经编写了访问网页的代码:
Sub login()
Dim IE As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://esp"
End Sub
Q2)我应该使用哪个createobject来访问Google Chrome?
Thnx提前
答案 0 :(得分:1)
Sub login()
Dim IE As Object
Dim HTMLDoc As Object
Dim objCollection As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://ogin.esp"
Do While IE.Busy Or IE.ReadyState <> 4: Loop
Set HTMLDoc = IE.document
With HTMLDoc
HTMLDoc.getElementById("USERNAME").Value = "yyyy"
HTMLDoc.getElementById("PASSWORD").Value = "xxxxx"
End With
Set objCollection = IE.document.getElementById("loginbutton")
objCollection.Click
End Sub
此代码有效....
答案 1 :(得分:0)
要在网页上查找要通过VBA选择的项目,您需要按F12进入网页上的开发人员工具。
在那里,您可以找到要通过&#34进入的元素;进入&#34;页面上的代码,并选择您希望VAB选择的项目。
以下是如何做到的:
然后选择用户名框:
选择此框后,开发人员框中的代码将突出显示,告诉您链接到所按项目的代码。
以下是用户名框的现在突出显示的代码:
我们有三个选项可以选择页面上的项目:
*注意:首先尝试使用ID,然后使用name,然后使用类,因为页面上只有1个元素将具有该1个ID,但是多个项目可以具有相同的名称或类别,或者保证其可以正常工作你有正确的身份证。
Dim IE As Object ' InternetExplorer.Application
Dim UserN As Object 'username field
Dim PW As Object 'password field
Dim LoginButton As Object 'Login button
'enter username and password in textboxes
Set UserN = IE.document.getElementByID("USERNAME")
'fill in first element named "username", assumed to be the login name field
UserN(0).Value = ""
Set PW = IE.document.getElementsByName("PASSWORD")
'fill in first element named "password", assumed to be the password field
PW(0).Value = ""
然后你需要找到页面上的按钮,然后单击它。 以下是一些代码:
'After entering in the user/pass, we need to click the button.
Dim objCollection As Object
Set objCollection = IE.document.getElementById("loginbutton")
objCollection.Click
有更多信息和更多关于如何正确使用每种选择方法的代码,所以这只是让你入门的准系统。 正在搜索VBA IE自动化&#39;能为你带来一些好的结果。