コード例 #1
0
ファイル: browser.go プロジェクト: jabbahotep/surf
// 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
}
コード例 #2
0
ファイル: browser.go プロジェクト: jabbahotep/surf
// 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())
}
コード例 #3
0
ファイル: form.go プロジェクト: jabbahotep/surf
// Input sets the value of a form field.
func (f *Form) Input(name, value string) error {
	found := false
	for _, f := range f.fields {
		if f.name == name {
			f.value = value
			found = true
		}
	}
	for _, c := range f.checkboxes {
		if c.name == name && c.value == value {
			if c.checked {
				c.checked = false
			} else {
				c.checked = true
			}
			found = true
		}
	}
	if found {
		return nil
	}
	return errors.NewElementNotFound(
		"No input found with name '%s'.", name)
}