Menu

How to click button that is NOT part of form

Help
Petr Svarc
2004-09-09
2013-04-26
  • Petr Svarc

    Petr Svarc - 2004-09-09

    Hi everybody!

    I need to test a web application that uses buttons with JavaScript for navigation. I need to click these buttons. And I can't figure out, how to get to the buttons, since they are not a part of a form.

    The code of the button is:

    <BUTTON name="Continue"  accesskey="C" class="formButton" onclick="window.open(...);"><U>C</U>ontinue</BUTTON>

    and it may appear anywhere in the page.

    Thanks for any ideas!

     
    • mike firth

      mike firth - 2004-11-09

      Hi,

      I have the same problem - a button that is not part of a form - so it is not possible to use any of the WebForm.getButton... methods.

      What about if we use

      HTMLElement[] buttons =  response.getElementsWithAttribute("type", "button");

      is there a way to convert an HTMLElement to a Button?

       
    • mike firth

      mike firth - 2004-11-10

      Petr and Russell,

      From reading the source it looks like HttpUnit 1.6's ParsedHTML class DOES handle your situation but not mine. It expects buttons outside forms to be one of these two styles:

      <button type="button" ...>
      <button ...> // ie. not type specified

      To get, say, the first button try this:

      HTMLElement[] buttons =
          frame.getElementsWithAttribute("type", "button");
      Button button = (Button) buttons[0];

      My problem is caused by the web page using the input tag outside a form:

      <input type="button" onclick="blahblah" value="OK">

      Consequently, it can't be found by frame.getElementsWithAttribute("type", "button")

      So, can someone help me?

      Is it legitimate to modify ParsedHTML.newControlWithoutForm( ParsedHTML parsedHTML, Element element ) from doing this:

      if (element.getNodeName().equalsIgnoreCase( "button" )
      && isValidNonFormButtonType( NodeUtils.getNodeAttribute( element, "type" ) ))

      to doing this:

      if ((element.getNodeName().equalsIgnoreCase( "button" )
          || element.getNodeName().equalsIgnoreCase( "input" ))
      && isValidNonFormButtonType( NodeUtils.getNodeAttribute( element, "type" ) ))

      Mike

       

Log in to post a comment.

MongoDB Logo MongoDB