github.com/MontFerret/ferret@v0.18.0/pkg/drivers/cdp/templates/blur.go (about) 1 package templates 2 3 import ( 4 "fmt" 5 6 "github.com/mafredri/cdp/protocol/runtime" 7 8 "github.com/MontFerret/ferret/pkg/drivers" 9 "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" 10 ) 11 12 const blur = `(el) => { 13 el.blur() 14 }` 15 16 func Blur(id runtime.RemoteObjectID) *eval.Function { 17 return eval.F(blur).WithArgRef(id) 18 } 19 20 var ( 21 blurByCSSSelector = fmt.Sprintf(` 22 (el, selector) => { 23 const found = el.querySelector(selector); 24 25 %s 26 27 found.blur(); 28 } 29 `, notFoundErrorFragment) 30 31 blurByXPathSelector = fmt.Sprintf(` 32 (el, selector) => { 33 %s 34 35 %s 36 37 found.blur(); 38 } 39 `, xpathAsElementFragment, notFoundErrorFragment) 40 ) 41 42 func BlurBySelector(id runtime.RemoteObjectID, selector drivers.QuerySelector) *eval.Function { 43 var f *eval.Function 44 45 if selector.Kind() == drivers.CSSSelector { 46 f = eval.F(blurByCSSSelector) 47 } else { 48 f = eval.F(blurByXPathSelector) 49 } 50 51 return f.WithArgRef(id).WithArgSelector(selector) 52 }