1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00
ferret/pkg/drivers/cdp/templates/get_inner_text.go
Tim Voronov 347bae2e45
Feature/#265 dom manipulations (#329)
* Added SetInnerHTML method

* Added E2E tests

* Refactored GetInnerText* methods

* Updated e2e tests

* Moved related E2E tests to folders

* Added error message

* Added E2E tests

* Added E2E for static driver
2019-07-11 17:16:34 -04:00

33 lines
651 B
Go

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