// Form returns the form in the current page that matches the given expr. func (bow *Browser) Form(expr string) (Submittable, error) { sel := bow.Find(expr) if sel.Length() == 0 { return nil, errors.NewElementNotFound( "Form not found matching expr '%s'.", expr) } if !sel.Is("form") { return nil, errors.NewElementNotFound( "Expr '%s' does not match a form tag.", expr) } return NewForm(bow, sel), nil }
// DeleteField deletes a form field func (f *Form) DeleteField(name string) error { if f.definedFields[name] { f.fields.Del(name) return nil } return errors.NewElementNotFound( "No input found with name '%s'.", name) }
// Input sets the value of a form field. func (f *Form) Input(name, value string) error { if f.definedFields[name] { f.fields.Set(name, value) return nil } return errors.NewElementNotFound( "No input found with name '%s'.", name) }
// Click clicks on the page element matched by the given expression. // // Currently this is only useful for click on links, which will cause the browser // to load the page pointed at by the link. Future versions of Surf may support // JavaScript and clicking on elements will fire the click event. func (bow *Browser) Click(expr string) error { sel := bow.Find(expr) if sel.Length() == 0 { return errors.NewElementNotFound( "Element not found matching expr '%s'.", expr) } if !sel.Is("a") { return errors.NewElementNotFound( "Expr '%s' must match an anchor tag.", expr) } href, err := bow.attrToResolvedUrl("href", sel) if err != nil { return err } return bow.httpGET(href, bow.Url()) }
// InputSlice sets the values of a form field. func (f *Form) InputSlice(name string, values []string) error { if f.definedFields[name] { f.fields.Del(name) for _, v := range values { f.fields.Add(name, v) } return nil } return errors.NewElementNotFound( "No input found with name '%s'.", name) }