[TIP] twill question

Brent Pedersen bpederse at gmail.com
Fri Jan 25 11:17:00 PST 2008


hi, i think this is what you want.

import twill.commands as tc
b = tc.get_browser()
tc.go("http://www.google.com")
forms = tc.showforms()
form = forms.next()
names = [control.name for control in form.controls]
print names


On Jan 25, 2008 11:01 AM, David Brochu <brochu121 at gmail.com> wrote:
> Thanks for the help Terry.
>
> Unfortunately the code you supplied only returns the values passed to
> the form fields, not the name of the form fields themselves. In your
> example what I would like to have returned is the form field "q", not
> the contents of q.
>
>
>
> On Jan 25, 2008, at 12:26 PM, Terry Peppers wrote:
>
> > Hi David.
> >
> >> I've been using Twill quite extensively for the past month or so and
> >> I love it.
> >
> > Same here.
> >
> >> I was just wondering, is there was a way to pull a field value
> >> directly from a form? I know you can use showforms() to view all
> >> available forms, but I really need to grab each field name from the
> >> form individually so my Python program can determine what type of
> >> info it should pass to each field.
> >
> > This probably isn't the most elegant way, but it's a way.
> >
> > ---- START SNIP -----
> >>>> from twill.commands import *
> >>>> go("http://www.google.com")
> > ==> at http://www.google.com
> > 'http://www.google.com'
> >
> >>>> fv(1, "q", "python and twill")
> >>>> f = get_browser().get_form("f")
> >>>> f.get_value("q")
> > 'python and twill'
> >>>>
> > ---- END SNIP -----
> >
> > From my understanding of Twill, you have to call the get_browser() and
> > get_form() methods. By passing the name of the form to the get_form()
> > method, you then should be able to use the get_value() method if you
> > pass it the name of the form field.
> >
> > I swear there's a better way. Maybe Titus can answer better.
> >
> > t.
> >
> > _______________________________________________
> > testing-in-python mailing list
> > testing-in-python at lists.idyll.org
> > http://lists.idyll.org/listinfo/testing-in-python
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>



More information about the testing-in-python mailing list