1
0
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:
Tim Voronov 2018-09-27 17:19:55 -04:00
parent 61c81fa03b
commit ef29241aa6
2 changed files with 23 additions and 3 deletions

4
docs/examples/value.fql Normal file
View 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'

View File

@ -8,6 +8,7 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"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/PuerkitoBio/goquery"
"github.com/mafredri/cdp"
@ -29,7 +30,7 @@ type HtmlElement struct {
nodeName values.String
innerHtml values.String
innerText *common.LazyValue
value values.String
value core.Value
attributes *common.LazyValue
children []dom.NodeID
loadedChildren *common.LazyValue
@ -203,7 +204,7 @@ func (el *HtmlElement) Unwrap() interface{} {
func (el *HtmlElement) Hash() int {
h := sha512.New()
out, err := h.Write([]byte(el.value))
out, err := h.Write([]byte(strconv.Itoa(int(el.id))))
if err != nil {
return 0
@ -213,7 +214,22 @@ func (el *HtmlElement) Hash() int {
}
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 {