在IE中使用alt点击img按钮的问题

时间:2018-04-13 06:23:01

标签: vba excel-vba dom click alt

我目前正在尝试点击没有ID的网站上的特定img按钮,因此我尝试基于alt进行点击。以下是来自DOM资源管理器,alt是日文字符。

<a href="/e-navi/members/statement/index.xhtml?tabNo=0">
<img width="112" height="23" alt="翌月以降" src="https://image.card.jp.rakuten-static.com/r-enavi/WebImages/enavi/common/tab05_after_o.gif">
</a>

我用来尝试点击链接的代码是:

pUnicodeString = ChrW(32716) & ChrW(26376) & ChrW(20197) & ChrW(38477)
Set tags = ie.document.getElementsByTagName("a")
For Each tagx In tags
    If tagx.getAttribute("alt") = pUnicodeString Then
        tagx.Click
    End If
Next

注意:我也尝试使用Set tags = ie.document.getElementsByTagName(“img”)。 运行代码时,如果tagx.getAttribute(“alt”)= pUnicodeString那么我得到“Permission Denied”错误。
我一直在许多网站上搜索,并尝试了许多人过去的例子但没有工作。以下是我的完整代码供参考。

Sub csvfetch()
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim div As HTMLDivElement
Dim url As String
Dim form As Variant
Dim button As Variant
Dim tags As Object
Dim tagx As Object

url = "https://www.rakuten-card.co.jp/e-navi/?l-id=corp_de_enavi_index_001"
Set ie = New SHDocVw.InternetExplorer
With ie
    .Visible = True
    .navigate url
    While .Busy
        DoEvents
    Wend
End With

    While ie.Busy
        DoEvents
    Wend
Application.Wait (Now + TimeValue("0:00:02"))
'temp user/pass
user = Sheets("Pass").Cells(2, 2)
pass = Sheets("Pass").Cells(2, 3)
ie.document.getElementById("u").Value = user
ie.document.getElementById("p").Value = pass
'login
Set form = ie.document.getElementsByTagName("form")
Set button = form(0).onsubmit
form(0).submit

    While ie.Busy
        DoEvents
    Wend

 Set ElementCol = ie.document.getElementsByClassName("rf-button-alt rce-white-button rf-mini")
 ElementCol.Item(0).Click
    While ie.Busy
        DoEvents
    Wend

pUnicodeString = ChrW(32716) & ChrW(26376) & ChrW(20197) & ChrW(38477)
Set tags = ie.document.getElementsByTagName("a")
For Each tagx In tags
    If tagx.getAttribute("alt") = pUnicodeString Then
        tagx.Click
    End If
Next

Set ie = Nothing
'Unload UserForm1
End Sub

0 个答案:

没有答案