mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-21 21:47:43 +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
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package html
|
|
|
|
import (
|
|
"context"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
)
|
|
|
|
// PRESS_SELECTOR presses a keyboard key.
|
|
// @param {HTMLPage | HTMLDocument | HTMLElement} node - Target html node.
|
|
// @param {String} selector - CSS selector.
|
|
// @param {String | String[]} key - Target keyboard key(s).
|
|
// @param {Int} [presses=1] - Count of presses.
|
|
func PressSelector(ctx context.Context, args ...core.Value) (core.Value, error) {
|
|
err := core.ValidateArgs(args, 3, 4)
|
|
|
|
if err != nil {
|
|
return values.False, err
|
|
}
|
|
|
|
el, err := drivers.ToElement(args[0])
|
|
|
|
if err != nil {
|
|
return values.False, err
|
|
}
|
|
|
|
selector, err := drivers.ToQuerySelector(args[1])
|
|
|
|
if err != nil {
|
|
return values.None, err
|
|
}
|
|
|
|
count := values.NewInt(1)
|
|
|
|
if len(args) == 4 {
|
|
countArg := values.ToInt(args[3])
|
|
|
|
if countArg > 0 {
|
|
count = countArg
|
|
}
|
|
}
|
|
|
|
keysArg := args[2]
|
|
|
|
switch keys := keysArg.(type) {
|
|
case values.String:
|
|
return values.True, el.PressBySelector(ctx, selector, []values.String{keys}, count)
|
|
case *values.Array:
|
|
return values.True, el.PressBySelector(ctx, selector, values.ToStrings2(keys), count)
|
|
default:
|
|
return values.None, core.TypeError(keysArg.Type(), types.String, types.Array)
|
|
}
|
|
}
|