1

I am currently trying to click on a specific img button on a site that does not have an Id so I am trying to click based on the alt. Below is from the DOM Explorer, the alt is in Japanese characters.

<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>

The code I am using to try and click the link is:

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

NOTE: I have also tried it with Set tags = ie.document.getElementsByTagName("img") as well. When running the code I get the "Permission Denied" error on If tagx.getAttribute("alt") = pUnicodeString Then.
I have been searching on many sites and have tried many peoples past examples but none worked. Below is my full code for reference.

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
Josh
  • 11
  • 2
  • Did you try `tagx.getAttribute("alt")` instead of `tagx.alt`? • If I paste `tagx.alt = "翌月以降"` into VBE it instantly converts to `tagx.alt = "????"` because it does not support unicode characters. If that is your issue too, you might have a look here: https://stackoverflow.com/a/23678551/3219613 – Pᴇʜ Apr 13 '18 at 07:34
  • @Pᴇʜ thank you for your quick response! I tried your advice but now I am getting "Permission Denied" error.... For now, I do not believe it is a character issue since the error occurs even before it touches the Japanese characters. As for the "????" I had the same issue pasting into my question; however, I have created a few macros with Japanese characters without any issues so I'm "assuming" that isn't the main problem. – Josh Apr 13 '18 at 07:52
  • Then probably this https://stackoverflow.com/a/31966364/3219613 is your issue. – Pᴇʜ Apr 13 '18 at 08:02
  • @Pᴇʜ Thanks for the link, I tweaked it a little and at least the code doesn't error anymore. Then I looked at the unicode issue and modified my code to search for pUnicodeString = ChrW(32716) & ChrW(26376) & ChrW(20197) & ChrW(38477) rather than "翌月以降." the variable contains the correct Japanese characters; however still getting "Permission Denied" – Josh Apr 13 '18 at 08:34
  • 1
    Please [edit] your question to reflect your current code and issue. – QHarr Apr 13 '18 at 08:37
  • Apologies, I forgot to save edits.....I have updated the code and error. – Josh Apr 13 '18 at 08:40

0 Answers0