Hi Emanuele,

When you talk about retrieving a submit button, I suppose you mean clicking on it?

Currently, you can use XPath : clickElementByXPath("//input[type='submit' and value='youre value']");

But you're right, we could make submit(String id) method to be more permissive, like this : submit(String valueOrId)
The problem is some people also need submitting elements by name. We could become more and more permissive with parameters :
submit(String nameOrValueOrIdOr...) but this way, you didn't assert precisly the type of your button.
Concider a stupid example like :
<input type="submit" name="foo">
<input type="submit" value="foo">
<input type="submit" id="foo">

The second possibility is to add another methods:
submit ById(String ID)
submitByName(String name)
submitByValue(String value)
...

But people always have new needs, more and more complicated (what about a method that checks if a button named 'foo' is present in the table with summary='bar' in cell (3, 4)?
assertButtonPresentInTableBySummaryWithName("foo","bar",3,4) ??

That's why, in most of the cases, I suggest to not change the current API. If someone is using the same action very often, why not creating it's own method :
public void submitByValue(String value) {
    clickElementByXPath("//input[type='submit' and value='" + value +"']");
}

Therefore, if a method is very popular and needed but many users, we will of course add it to the core API, and perhaps it is the case with submitting a button by value...

Concerning your proposition, if you want to contribute to jWebUnit, you can of course send me patch, and I will apply it after taking a look on it ;)

++

Julien

----- Message d'origine ----
De : Emanuele Gesuato <[EMAIL PROTECTED]>
À : [email protected]
Envoyé le : Lundi, 4 Septembre 2006, 2h30mn 56s
Objet : [Jwebunit-users] Simple way to retrieve a submit button by value

Hi there,
I'm using jwebUnit with HtmlUnit plugin and I would like to have a
simple way to retrieve a submit button by value.

I haven't seen any immediate method to do this, so i managed to write
a method myself in HtmlUnitDialog class. I hope it will be useful to
anyone who have got the same problem and i hope that Julien add this
(or similar) feature to retrieve a submit button by value.

It would be useful to handle that kinds of button throgh "clickButton" method.
Do you need developers Julien ? :-)

*****
    public HtmlSubmitInput getSubmitButtonWithText(String valueText) {        
        List l = ((HtmlPage) win.getEnclosedPage()).getDocumentElement()
                .getHtmlElementsByAttribute("input", "type", "submit");        
        for (int i = 0; i < l.size(); i++) {
            HtmlElement e = (HtmlElement) l.get(i);

            if (((HtmlSubmitInput) e).getValueAttribute().equals(valueText))
                return (HtmlSubmitInput) e;
        }
        return null;
    }

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jwebunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-users

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jwebunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-users

Reply via email to