1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/drivers/cdp/templates/get_inner_text.go
Tim Voronov 6ec50c5e43
Bugfix/inner text html by selector (#347)
* Fixed inner text

* Fixed inner html

* Updated set inner html and inner text

* Changed mechanism of reading and writing inner text and html

* updated makefile

* Added e2e tests

* Updated makefile

* Updated changelog

* Reverted dynamic page example
2019-08-05 19:57:02 -04:00

41 lines
735 B
Go

package templates
import (
"fmt"
"github.com/MontFerret/ferret/pkg/drivers"
)
var getInnerTextBySelectorTemplate = fmt.Sprintf(`
(el, selector) => {
const found = el.querySelector(selector);
if (found == null) {
throw new Error("%s");
}
return found.innerText;
}
`, drivers.ErrNotFound,
)
func GetInnerTextBySelector() string {
return getInnerTextBySelectorTemplate
}
var getInnerTextBySelectorAllTemplate = fmt.Sprintf(`
(el, selector) => {
const found = el.querySelectorAll(selector);
if (found == null) {
throw new Error("%s");
}
return Array.from(found).map(i => i.innerText);
}
`, drivers.ErrNotFound,
)
func GetInnerTextBySelectorAll() string {
return getInnerTextBySelectorAllTemplate
}