// 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 }
// Input sets the value of a form field. func (f *Form) Input(name, value string) error { if _, ok := f.fields[name]; ok { 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()) }