From e12e5d1f15749a42d0fd08cc6f0eb4cd1ed813e7 Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Sat, 18 Feb 2017 10:39:11 +0700 Subject: [PATCH] Fixing Clear action to properly work with textarea nodes --- query.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/query.go b/query.go index a4406d9..81a35a7 100644 --- a/query.go +++ b/query.go @@ -135,7 +135,23 @@ func Clear(sel interface{}, opts ...QueryOption) Action { if n.NodeName == "INPUT" { a = dom.SetAttributeValue(n.NodeID, "value", "") } 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) }(i, n)