Skip to content

Commit

Permalink
Support element screenshot (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
llonchj authored and minusnine committed Oct 6, 2018
1 parent 31a4f14 commit 3013caa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -1438,3 +1438,15 @@ func (elem *remoteWE) MarshalJSON() ([]byte, error) {
webElementIdentifier: elem.id,
})
}

func (elem *remoteWE) Screenshot(scroll bool) ([]byte, error) {
data, err := elem.parent.stringCommand(fmt.Sprintf("/session/%%s/element/%s/screenshot", elem.id))
if err != nil {
return nil, err
}

// Selenium returns a base64 encoded image.
buf := []byte(data)
decoder := base64.NewDecoder(base64.StdEncoding, bytes.NewBuffer(buf))
return ioutil.ReadAll(decoder)
}
2 changes: 2 additions & 0 deletions selenium.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,6 @@ type WebElement interface {
// CSSProperty returns the value of the specified CSS property of the
// element.
CSSProperty(name string) (string, error)
// Screenshot takes a screenshot of the attribute scroll'ing if necessary.
Screenshot(scroll bool) ([]byte, error)
}

0 comments on commit 3013caa

Please sign in to comment.