mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-19 21:28:32 +02:00
* Added remote type reference resolver * Added support of XPath query selector * Added CDP e2e testss covering XPath integration * Added additional CDP e2e tests covering XPath integration * Added type check to QuerySelector casting function * Fixed XPath e2e tests * Fixed vuln issue * Added support of XPath selectors to http driver * Added e2e tests for XPAth
40 lines
944 B
Go
40 lines
944 B
Go
package html
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
)
|
|
|
|
// INNER_TEXT returns inner text string of a given or matched by CSS selector element
|
|
// @param {HTMLPage | HTMLDocument | HTMLElement} node - Target html node.
|
|
// @param {String} [selector] - String of CSS selector.
|
|
// @return {String} - Inner text if a matched element, otherwise empty string.
|
|
func GetInnerText(ctx context.Context, args ...core.Value) (core.Value, error) {
|
|
err := core.ValidateArgs(args, 1, 2)
|
|
|
|
if err != nil {
|
|
return values.EmptyString, err
|
|
}
|
|
|
|
el, err := drivers.ToElement(args[0])
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
if len(args) == 1 {
|
|
return el.GetInnerText(ctx)
|
|
}
|
|
|
|
selector, err := drivers.ToQuerySelector(args[1])
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
return el.GetInnerTextBySelector(ctx, selector)
|
|
}
|