mirror of
https://github.com/MontFerret/ferret.git
synced 2025-04-21 12:16:53 +02:00
Added dynamic Element.value
This commit is contained in:
parent
61c81fa03b
commit
ef29241aa6
4
docs/examples/value.fql
Normal file
4
docs/examples/value.fql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
LET doc = DOCUMENT("https://www.yandex.com/search/?text=foobar", true)
|
||||||
|
LET input = ELEMENT(doc, 'input[type="search"]')
|
||||||
|
|
||||||
|
RETURN input.value ? input.value : 'value not defined'
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/MontFerret/ferret/pkg/runtime/core"
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
||||||
"github.com/MontFerret/ferret/pkg/runtime/values"
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||||||
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/common"
|
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/common"
|
||||||
|
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/dynamic/eval"
|
||||||
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/dynamic/events"
|
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/dynamic/events"
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/mafredri/cdp"
|
"github.com/mafredri/cdp"
|
||||||
@ -29,7 +30,7 @@ type HtmlElement struct {
|
|||||||
nodeName values.String
|
nodeName values.String
|
||||||
innerHtml values.String
|
innerHtml values.String
|
||||||
innerText *common.LazyValue
|
innerText *common.LazyValue
|
||||||
value values.String
|
value core.Value
|
||||||
attributes *common.LazyValue
|
attributes *common.LazyValue
|
||||||
children []dom.NodeID
|
children []dom.NodeID
|
||||||
loadedChildren *common.LazyValue
|
loadedChildren *common.LazyValue
|
||||||
@ -203,7 +204,7 @@ func (el *HtmlElement) Unwrap() interface{} {
|
|||||||
func (el *HtmlElement) Hash() int {
|
func (el *HtmlElement) Hash() int {
|
||||||
h := sha512.New()
|
h := sha512.New()
|
||||||
|
|
||||||
out, err := h.Write([]byte(el.value))
|
out, err := h.Write([]byte(strconv.Itoa(int(el.id))))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0
|
return 0
|
||||||
@ -213,7 +214,22 @@ func (el *HtmlElement) Hash() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (el *HtmlElement) Value() core.Value {
|
func (el *HtmlElement) Value() core.Value {
|
||||||
return values.None
|
if !el.IsConnected() {
|
||||||
|
return el.value
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := contextWithTimeout()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
val, err := eval.Property(ctx, el.client, el.id, "value")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return el.value
|
||||||
|
}
|
||||||
|
|
||||||
|
el.value = val
|
||||||
|
|
||||||
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HtmlElement) Clone() core.Value {
|
func (el *HtmlElement) Clone() core.Value {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user