我想通过VBA编写代码以自动登录网站。
而登录"按钮"实际上是一个"登录图像",没有id或Name。 我不知道如何让 VBA 在"登录图像"上执行"鼠标左键单击"。
另外,我注意到当我将鼠标移动到"登录图像"上时,左下角显示:smcvdollogon
愿这有帮助...我根本不了解javascript
这是这样的:
<TD align=right width="20%" height="21"><input type="image" src="../img/DL.jpg" width="63" height="22" border="0" onClick="javascript:submitform();" style="cursor: pointer;"></TD>
这是提交表单():
<script>
function submitform(){
if(FRM.authId.value==''){
alert("please enter user name!");
FRM.authId.focus();
return false;
}else{
FRM.submit();
}
}
function reset_text(){
document.getElementById('username').focus();
}
</script>
这是我的代码,仍然缺少最后一步:('###the 网站无法从我们公司访问###)
Sub macro1()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://10.90.15.247/smcvDolWeb/jsp/login.htm"
While ie.busy Or ie.readystate <> 4
Wend
ie.Document.getElementById("username").Value = "admin"
ie.Document.getElementById("password").Value = "1234"
End Sub
任何帮助将不胜感激。
按类型获取对象 getElementsByTagName,然后循环查找正确的对象
这将遍历页面上的每个TD项目。 一旦它击中具有相同 SRC 的 src,它就会单击它。
如果您不想每次都这样做,并且网页没有太大变化,您可以直接调试。打印 cnt 并执行 ie.document.all.tags("td").item(cnt).单击
让我知道这是否有效。
Dim Cnt As Variant
Dim oCell As Object
Cnt = 0 '
With ie.Document.all
For Each oCell In .tags("td")
If oCell.src = "../img/DL.jpg" Then
ocell.click
ocell.fireevent("submit") 'aircode, might have to be moved.
Exit For
End If
Cnt = Cnt + 1
Next oCell
End With
此外,如果您将"TD"替换为"图像",它可能会更快地工作
你需要运行的javascript将是.fireevent("submit")甚至可能是onchange。