How to simulate a Google search

205 views
Skip to first unread message

Carl Youngblood

unread,
Jul 28, 2010, 4:37:29 AM7/28/10
to webrat
I've been working on a script to simulate a Google search and getting
a little stuck. Depending on what country you're in, Google's search
button is translated into various languages. So I want to find and
click a button whose title matches a regular expression, rather than
finding a button with exact text.

I would also like to figure out how to find a button by name (not id
or title). Can somebody help me with this?

Thanks,
Carl

Curran Schiefelbein

unread,
Jul 28, 2010, 9:25:10 AM7/28/10
to web...@googlegroups.com
You can use a CSS selector to find an element by any attribute:

selenium.get_value('css=input[name=btnG]')

That drops down into selenium; not sure whether you're using selenium
with webrat, but it's easier sometimes when you need to get specific
with your locators. Webrat makes too many assumptions in click_button
and click_link for my tastes. Of course you can always tweak webrat
itself to accept a selector, instead of constructing one for you, if
you don't want to use selenium. :)

Also, the FireFinder plugin for Firefox/Firebug is invaluable for
sanity checking CSS selectors.

Curran

> --
> You received this message because you are subscribed to the Google Groups "webrat" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to webrat+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webrat?hl=en.
>
>

Curran Schiefelbein

unread,
Jul 28, 2010, 9:27:54 AM7/28/10
to web...@googlegroups.com
Oops -- that should have read

selenium.click('css=input[name=btnG]')

And I meant to point you to the very thorough reference on CSS
selectors: http://www.w3.org/TR/css3-selectors/#selector-syntax

Curran

Reply all
Reply to author
Forward
0 new messages