clicking web site button that has "input name"

  • Hi all,


    I came across a button on a web site that has very similar setup as the small button on this page. I'm talking about the search buttton (the tinny magnifying glass closes to the top on the right side)
    Is there any way to click this button with excel vba code?


    Hope some one is able to help out.


    Greetings.

  • Re: clicking web site button that has "input name"


    One way:

  • Re: clicking web site button that has "input name"


    Hi John,


    Did not work :-(
    The setup of the buttons is so similar that it could have worked:


    My button:

    Code
    1. <input name="btnRetrieveWorkItem" class="iwHomePgNavButt" type="submit" value="Retrieve Work Item"/>


    Button from this site:

    Code
    1. <input name="submit" tabIndex="100" class="searchbutton" onclick="document.getElementById('navbar_search').submit;" type="image" src="images/buttons/search.png" complete="complete"/>


    There must be a little thing that keeps it from working.


    Greetings.

  • Re: clicking web site button that has &quot;input name&quot;


    It works for the Ozgrid HTML because it is written specifically for that HTML. You need to modify the code to suit your specific HTML. IE automation is always like that; one bit of code doesn't necessarily work on another web page.


    Look at the 'name' attribute of the Ozgrid HTML and see how that is used in the code. Does that give you a clue for modifying the code to make it work with your HTML?

  • Re: clicking web site button that has &quot;input name&quot;


    Hi John,


    I guess it has to do something with this part:

    Code
    1. value="Retrieve Work Item"

    but no clue how to fit that one :-(
    When I saw that the buttons had the same biginning setup, I really was hopoing it would work.


    the Ozgrid button has an: onclick, maybe this is also a part to look at.


    Greetings.

  • Re: clicking web site button that has &quot;input name&quot;


    Quote from megatronixs;751271


    I guess it has to do something with this part:

    Code
    1. value="Retrieve Work Item"

    No. The name attribute is the part name="submit".


    The getElementsByName method relates to the name attribute in HTML tags, hence:

    Code
    1. .Document.getElementsByName("submit")(0).Click

    Your name attribute is name="btnRetrieveWorkItem", so the code should be:

    Code
    1. .Document.getElementsByName("btnRetrieveWorkItem")(0).Click

    assuming the name "btnRetrieveWorkItem" in the HTML you posted is the first occurrence of that name - the (0) array/collection index in the code.

  • Re: clicking web site button that has &quot;input name&quot;


    Hi,


    All I get is error 91, Object variable or With block variable not set.


    The button is in a frame:

    Code
    1. <frame name="frame1" src="HomeAction.do" marginWidth="0" marginHeight="0" noResize="noresize" scrolling="yes">


    Maybe that is the problem.


    This is the main form:

    Code
    1. <frameset name="main" cols="49%,51%" onfocus="giveFocus()" onload="giveFocus()">


    When that button is pushed, in frame 3 there will be content, and there is the next button I also want to press.


    Greetings.

  • Re: clicking web site button that has &quot;input name&quot;


    In that case you first need to get the document within the frame. Something like:

    Code
    1. Dim HTMLdoc As HTMLDocument
    2. Set HTMLdoc = .document.frames("frame1").document
    3. HTMLdoc.getElementsByName("btnRetrieveWorkItem")(0).Click

    within your With ... block.

  • Re: clicking web site button that has &quot;input name&quot;


    Hi John,


    You are my super heroe :-)


    That really worked out an paved the road to be able to click the other buttons and fill in the fields :-)



    BIG BIG BIG THANKS.


    I hope some one can make use of this too.


    Greetings.

  • Re: clicking web site button that has &quot;input name&quot;


    Hi all,


    I was wondering if it is possible to run the macro again and if I'm still on the same website, not reopen the link again, but run the code after the part that clicks the button.
    Is it possible?


    Greetings.

  • Re: clicking web site button that has &quot;input name&quot;


    Loop through Shell.Windows looking for an IE window and IE.locationURL = your website URL (or IE.locationName, or IE.document.title = your website title). If found, use that IE.document else open a new IE window and IE.Navigate to your URL. There should be examples of code if you search.