8000 Feature/add support for manipulating forms by jtwatson · Pull Request #131 · headzoo/surf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature/add support for manipulating forms #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ func (bow *Browser) SetHeadersJar(h http.Header) {
bow.headers = h
}

// SetTransport sets the http library transport mechanism for each request.
// SetTimeout sets the timeout for requests.
func (bow *Browser) SetTimeout(t time.Duration) {
if bow.client == nil {
Expand Down
27 changes: 25 additions & 2 deletions browser/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
type Submittable interface {
Method() string
Action() string

// SetAction will change the forms Action to the provided url
SetAction(url string) error

Input(name, value string) error
Set(name, value string) error

Expand Down Expand Up @@ -65,6 +69,9 @@ type Submittable interface {
// It will add the field to the form if necessary
SetFile(name string, fileName string, data io.Reader)

// AddButton adds a new button to the collection of buttons in the form, with the given name and value.
AddButton(name, value string)

Click(button string) error
ClickByValue(name, value string) error
Submit() error
Expand Down Expand Up @@ -113,6 +120,17 @@ func (f *Form) Action() string {
return f.action
}

// SetAction sets the form action URL.
// The provided URL may be relitive or absolute
func (f *Form) SetAction(url string) error {
action, err := f.bow.ResolveStringUrl(url)
if err != nil {
return err
}
f.action = action
return nil
}

// Input sets the value of a form field.
// it returns an ElementNotFound error if the field does not exist
func (f *Form) Input(name, value string) error {
Expand Down Expand Up @@ -293,6 +311,11 @@ func (f *Form) Submit() error {
return f.send("", "")
}

// AddButton adds a new button to the collection of buttons in the form, with the given name and value.
func (f *Form) AddButton(button, value string) {
f.buttons.Add(button, value)
}

// Click submits the form by clicking the button with the given name.
func (f *Form) Click(button string) error {
if _, ok := f.buttons[button]; !ok {
Expand Down Expand Up @@ -333,8 +356,8 @@ func (f *Form) send(buttonName, buttonValue string) error {
if !ok {
method = "GET"
}
action, ok := f.selection.Attr("action")
if !ok {
action := f.action
if action == "" {
action = f.bow.Url().String()
}
aurl, err := url.Parse(action)
Expand Down
0