【发布时间】:2016-01-10 13:25:35
【问题描述】:
我目前正在为在 saleforce 中上传文件进行自动化操作。
HTML 文本是:
<div>
<a href="javascript:void(0);" onblur="chatter.getFeed().contentCommentActionBlur(this);" onfocus="chatter.getFeed().contentCommentActionFocus(this);" onclick="chatter.getFeed().createContentComment(this,'0D52700002cc67d', false, true);" onmousedown="chatter.getFeed().contentCommentActionMouseDown(this);" class="cxcontentcommentaction">
<img class="cxcontentcommentactionimg" src="/s.gif">
<span class="cxcontentcommentactiontext">Attach File</span>
</a>
</div>
点击锚点的用户需要向下按“附加文件”按钮。
我尝试了两种不同的做法
1.编码通过anchor class="cxcontentcommentaction"获取元素:
Set htmldoc = mydoc.getElementsByClassName("cxcontentcommentaction")
htmldoc.Click
2.Coding通过span class="cxcontentcommentactiontext"获取元素:
Set htmldoc = mydoc.getElementsByClassName("cxcontentcommentactiontext")
htmldoc.Click
对于这两个我都收到错误“对象不支持此属性
在你的评论之后,我试过这样,
Set oElementCollection = mydoc.getElementsByClassName("cxcontentcommentactiontext")
For Each link In oElementCollection
If link.innerHTML = "Attach File" Then
link.Click
Exit For
End If
Next link
我已经尝试过以下 HTML
<a href="javascript:window.invokeOnClickJS_00bG0000000ikPK%28this%29" class="menuButtonMenuLink">
Send an Email</a>
下面的代码对上面的html正常工作
Set oElementCollection = mydoc.getElementsByClassName("menuButtonMenuLink")
For Each link In oElementCollection
If link.innerHTML = "Send an Email" Then
link.Click
Exit For
End If
Next link
但是这个问题中提到的“附加文件”按钮只会出现问题。
【问题讨论】:
-
看起来这应该是表单元素的一部分 - 在这种情况下,只需使用
Forms(0).Submit将0更改为正确的索引。
标签: vba excel internet-explorer automation