Fixing Clear action to properly work with textarea nodes

This commit is contained in:
Kenneth Shaw 2017-02-18 10:39:11 +07:00
parent 21d13b8f0a
commit e12e5d1f15

View File

@ -135,7 +135,23 @@ func Clear(sel interface{}, opts ...QueryOption) Action {
if n.NodeName == "INPUT" { if n.NodeName == "INPUT" {
a = dom.SetAttributeValue(n.NodeID, "value", "") a = dom.SetAttributeValue(n.NodeID, "value", "")
} else { } else {
a = dom.SetNodeValue(n.NodeID, "") // find textarea's child #text node
var textID cdp.NodeID
var found bool
for _, c := range n.Children {
if c.NodeType == cdp.NodeTypeText {
textID = c.NodeID
found = true
break
}
}
if !found {
errs[i] = fmt.Errorf("textarea node %d does not have child #text node", n.NodeID)
return
}
a = dom.SetNodeValue(textID, "")
} }
errs[i] = a.Do(ctxt, h) errs[i] = a.Do(ctxt, h)
}(i, n) }(i, n)