Why doesn't this simple Webspec script work?

710 views
Skip to first unread message

djangofan

unread,
Mar 29, 2011, 5:01:09 PM3/29/11
to watij
Why doesn't this simple Webspec script work? It runs but it wont
click the button.

---------------

import org.watij.webspec.dsl.WebSpec;
public class GoogleTest {

public static void main(String[] args) {
// TODO Auto-generated method stub
WebSpec spec = new WebSpec().mozilla();
spec.open("http://www.google.com");
spec.find.input().with.name("q").set.value("Dogs");
spec.find.button().with.name("btnG").click();
}

}

djangofan

unread,
Mar 29, 2011, 5:01:58 PM3/29/11
to watij
The error I get is :

Exception in thread "main" java.lang.RuntimeException: Expectation
failed: Element should exist before calling CLICK
at org.watij.webspec.dsl.Tag.shouldExist(Tag.java:332)
at org.watij.webspec.dsl.Tag.click(Tag.java:260)
at org.watij.webspec.dsl.Tag.click(Tag.java:255)
at GoogleTest.main(GoogleTest.java:14)

djangofan

unread,
Mar 29, 2011, 7:11:53 PM3/29/11
to watij
I found a solution but why did I need to have the single-quotes inside
the double-quotes? This is really un-intuitive and the documentation
on your site says nothing about this type of enclosure. I got it
working but there must be an easier way isn't there?

Here is the working code, with difficulty:


public static void main(String[] args) {
// TODO Auto-generated method stub
WebSpec spec = new WebSpec().mozilla();
spec.open("http://www.google.com"); //opens google.com in
Mozilla
spec.find.input().with.name("q").set.value("Dogs");
//spec.timeout(5000).find.button().with("name",
"btnG").click();
Tag loginBtn = spec.find("input").with("name=='btnG'");
loginBtn.click();
spec.pauseUntilReady();

}

Brian Knorr

unread,
Mar 29, 2011, 7:40:41 PM3/29/11
to watij
I am a little confused on what issues you are having? The
documentation http://watij.com/webspec-api/ has examples in almost
every section for doing this. Take a look at the very first example
under "Finding Tags" :

Tag input = spec.find("input").with("name=='myinput'");

djangofan

unread,
Mar 29, 2011, 8:08:05 PM3/29/11
to watij
Your right. My confusion was that my initial guess was do do it this
way:

spec.find("button").with("name", "myinput")
or
spec.find("button").at(0).click()

But both of those didn't work, despite their intuitiveness...

But, your right, the lesser intuitive answer worked:

spec.find("input").with("name=='myinput'");


-Jon



On Mar 29, 4:40 pm, Brian Knorr <btkn...@gmail.com> wrote:
> I am a little confused on what issues you are having?  The
> documentationhttp://watij.com/webspec-api/has examples in almost
> >     }- Hide quoted text -
>
> - Show quoted text -

Brian Knorr

unread,
Mar 31, 2011, 12:05:41 PM3/31/11
to watij
All the ways you mentioned should work as well...if not please send us
some example html that reproduces your issues...thanks,

Brian

On Mar 29, 7:08 pm, djangofan <django...@gmail.com> wrote:
> Your right.  My confusion was that my initial guess was do do it this
> way:
>
>    spec.find("button").with("name", "myinput")
>       or
>    spec.find("button").at(0).click()
>
> But both of those didn't work, despite their intuitiveness...
>
> But, your right, the lesser intuitive answer worked:
>
>     spec.find("input").with("name=='myinput'");
>
> -Jon
>
> On Mar 29, 4:40 pm, Brian Knorr <btkn...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I am a little confused on what issues you are having?  The
> > documentationhttp://watij.com/webspec-api/hasexamples in almost
Message has been deleted

Brian Knorr

unread,
Mar 31, 2011, 12:26:33 PM3/31/11
to watij
Google's search button is an html tag of "input" not "button"....so

spec.find.button().with.name("btnG").click();

...should instead be:

spec.find.input().with.name("btnG").click();

On Mar 31, 11:13 am, djangofan <django...@gmail.com> wrote:
> I already said the example.  The test above was for the Google search
> page, which everyone has access to.

djangofan

unread,
Mar 31, 2011, 12:27:48 PM3/31/11
to watij
I can't believe I didn't notice that. Sorry!

djangofan

unread,
Mar 31, 2011, 12:26:38 PM3/31/11
to watij
In the Google example that I gave that started this thread, I used
this example to click the button on the Google search page, but it
fails:

spec.find.button().with.name("btnG").click();


Maybe you can talk about why that would fail? What exactly was wrong
with that code statement above?
Reply all
Reply to author
Forward
0 new messages