Click button on website that is an image

  • Hi all,


    I have trouble clicking on a button that is actually an image inside a table from a website. I did manage other buttons, but this is not similar.


    HTML
    1. <td title="" role="gridcell" aria-describedby="objektsps_sps_class" espis-allow-action="true">


    the second part just below:

    HTML
    1. <img title="Doručený dokument" alt="Doručený dokument" src="img/doc_dorucpis_e.gif" complete="complete" hodnota="DorucenaPisemnost"/>


    I have no clue how to deal with this and can't find no answer nowhere.


    It is inside table with tabindex of "1" and then goes to tabindex "-1"
    It is inside a form that is called "filterform"


    Can some one help me on the right track?


    Greetings.


    This question was also posted here:
    http://www.excelforum.com/exce…e-button.html#post3638964

  • Re: Click button on website that is an image


    Hi John,
    Thanks for the info, but how do I kind of look through the collection? my vba knowledge is still kind of green :-)
    Can you give me an example how it would look like?


    greetings.

  • Re: Click button on website that is an image


    also cross posted here http://www.xtremevbtalk.com/showthread.php?t=298964


    read this link


    can you provide all back reference cross links in all the other forums you have posted

    Code
    1. Set GetHTMLImages = htmlDoc.images
  • Re: Click button on website that is an image


    Hi Pike,


    The above link to a cross post is not mine :-)
    I did for sure check that one to see if I could get something there too, but not my post.
    I only had it in http://excelforum.com in a another thread by me to combine some vba macros in one.


    I really appriciate the help from others and I hope the threads I started will be to some value to others.


    I guess I could make use of the below code, but I think it needs to be adjusted to the code from John W's post above.


    Code
    1. For Each SubmitInput In .getElementsByTagName("INPUT")
    2. If InStr(SubmitInput.getAttribute("onclick"), "AUTHENTICATE") Then
    3. SubmitInput.FireEvent "onclick"
    4. Exit For
    5. End If
    6. Next
    7. End With


    Greetings.

  • Re: Click button on website that is an image


    Try something like this, where IE is the InternetExplorer object with the page loaded:

    Note that "Doručený dokument" comes out as "Doruc(ený dokument" in the VBA code. I'm not sure how you would get round that; maybe use Instr to see if "dokument" occurs in Title instead.

  • Re: Click button on website that is an image


    Hi John,


    Done, just updated the tread with the link to this one.


    I tried your code, but it can't find the image. I tried to change few things, no luck. What about to use the below in a different way:


    Quote

    Loop through the IE.document.images collection looking for IE.document.images(n).Title = "Doručený dokument".


    I hope something is possible.


    Greetings.

  • Re: Click button on website that is an image


    Hi John,


    What about setting focus on the image to see if it is there.
    Should I not look instead of the image it self "img/doc_dorucpis_e.gif" as on the title it does not do nothing.
    I checked in another image I found that was only 1 word, and it said it found image (but does not click it).


    This is the one he found:


    HTML
    1. <a href="#spsNasTree" jQuery17208171055500510271="24">
    2. <img title="Nastavení" class="nastaveni" src="img/lightstyle/nastaveni.png" complete="complete"/>


    Maybe This I could click :-)


    Greetings.

  • Re: Click button on website that is an image


    As I said, try Instr instead:

    Code
    1. If InStr(1, HTMLdoc.images(i).Title, "dokument") > 0 Then Set image = HTMLdoc.images(i)


    If the required image with title containing "dokument" is not the first such image then that code will not find the correct image. If so, put "Doručený dokument" without the quotes in cell A1 of the active sheet and change the If statement to:

    Code
    1. If HTMLdoc.images(i).Title = Range("A1").Value Then Set image = HTMLdoc.images(i)


    If still no joy post the URL of the page.

  • Re: Click button on website that is an image


    Hi John,


    I can't give the URL as for security reasons we are not allowed to share.
    I found that there is a text inside the page that has the same word. It get's there and as there is no image, it will not find the image.
    Maybe we can tell the code to look for the second word, then it should find the image (I guess) ;-)


    Any idea how to get this?


    Greetings.

  • Re: Click button on website that is an image


    Quote from megatronixs;709269

    I found that there is a text inside the page that has the same word. It get's there and as there is no image, it will not find the image.

    My code only looks at the title text in IMG tags (the document.images collection), so will not find the same text in any other tag.


    Quote


    Maybe we can tell the code to look for the second word, then it should find the image (I guess) ;-)

    Increment another counter in the While Wend loop when an image with the required title text is found and exit the loop when this counter = 2.

  • Re: Click button on website that is an image


    Hi John,


    No idea how to do that. Can you let me know which part:


  • Re: Click button on website that is an image


    Like this:

    Note that "Doručený Dokument" copied and pasted into VBA comes out as "Doruc(ený Dokument" in my VBA editor, which obviously does not match the title or alt "Doručený Dokument" when the code is run. I don't know if this happens with your VBA editor. If necessary, use one of the suggestions I previously posted to get round this.

  • Re: Click button on website that is an image


    Hi John,


    The text pasted in my VBA editor appears correctly. Maybe has to do with the language settings, no clue. Tomorrow at work I will give it a try.
    On the other part, the previous button that I also could not click, now I could. It was just one word compared with the other that is two words. (Nastavení vs Doručený dokument
    ). It could related.

    Greetings and thanks for your great help on this!!!


  • Re: Click button on website that is an image


    Hi,


    I found the below code in:
    http://stackoverflow.com/quest…g-attribute-values-in-vba


    I did check to find all images, The one button I was able to click does not appear when I run the code. (I made some changes to accommodate my code).
    If I could it get to find all the images in the whole page including the other images in all the forms.
    Do you know how to do this?




    Greetings

  • Re: Click button on website that is an image


    Hi John,


    I found the following:


    HTML
    1. <table tabIndex="1"


    I guess this has to do with it.


    In my code to press one of the buttons I have:



    And it finds the button as it is on the first form in the page. I guess then it is not needed to put the tabindex nr. but as I'm new to all of this, no way to say what it could be.


    Greetings.