summaryrefslogtreecommitdiff
path: root/vendor/github.com/playwright-community/playwright-go/file_chooser.go
blob: 119e885886c6022fc93b5e23ee5ce4da29592537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package playwright

type fileChooserImpl struct {
	page          Page
	elementHandle ElementHandle
	isMultiple    bool
}

func (f *fileChooserImpl) Page() Page {
	return f.page
}

func (f *fileChooserImpl) Element() ElementHandle {
	return f.elementHandle
}

func (f *fileChooserImpl) IsMultiple() bool {
	return f.isMultiple
}

// InputFile represents the input file for:
// - FileChooser.SetFiles()
// - ElementHandle.SetInputFiles()
// - Page.SetInputFiles()
type InputFile struct {
	Name     string `json:"name"`
	MimeType string `json:"mimeType,omitempty"`
	Buffer   []byte `json:"buffer"`
}

func (f *fileChooserImpl) SetFiles(files interface{}, options ...FileChooserSetFilesOptions) error {
	if len(options) == 1 {
		return f.elementHandle.SetInputFiles(files, ElementHandleSetInputFilesOptions(options[0]))
	}
	return f.elementHandle.SetInputFiles(files)
}

func newFileChooser(page Page, elementHandle ElementHandle, isMultiple bool) *fileChooserImpl {
	return &fileChooserImpl{
		page:          page,
		elementHandle: elementHandle,
		isMultiple:    isMultiple,
	}
}