Adding ElementNotPresent/WaitNotPresent query option/action

This commit is contained in:
Kenneth Shaw 2017-02-08 23:16:28 +07:00
parent 6769aefc5e
commit 6eec61e7df
2 changed files with 19 additions and 0 deletions

View File

@ -48,6 +48,7 @@ func submit(urlstr, sel, q string, res *string) cdp.Tasks {
cdp.WaitVisible(sel),
cdp.SendKeys(sel, q),
cdp.Submit(sel),
cdp.WaitNotPresent(`//*[@id="code_search"]/h2/svg`),
cdp.Text(`//*[@id="js-pjax-container"]/div[2]/div/div[2]/ul/li/p`, res),
}
}

18
sel.go
View File

@ -27,6 +27,7 @@ tagname
// Error types.
var (
ErrNoResults = errors.New("no results")
ErrHasResults = errors.New("has results")
ErrNotVisible = errors.New("not visible")
ErrVisible = errors.New("visible")
ErrDisabled = errors.New("disabled")
@ -483,6 +484,18 @@ func ElementSelected(s *Selector) {
}))(s)
}
// ElementNotPresent is a query option to wait until no elements match are
// present matching the selector.
func ElementNotPresent(s *Selector) {
s.exp = 0
WaitFunc(func(ctxt context.Context, h cdp.FrameHandler, n *cdp.Node, ids ...cdp.NodeID) ([]*cdp.Node, error) {
if len(ids) != 0 {
return nil, ErrHasResults
}
return []*cdp.Node{}, nil
})(s)
}
// AtLeast is a query option to wait until at least n elements are returned
// from the query selector.
func AtLeast(n int) QueryOption {
@ -525,6 +538,11 @@ func WaitSelected(sel interface{}, opts ...QueryOption) Action {
return Query(sel, append(opts, ElementSelected)...)
}
// WaitNotPresent waits until no elements match the specified selector.
func WaitNotPresent(sel interface{}, opts ...QueryOption) Action {
return Query(sel, append(opts, ElementNotPresent)...)
}
const (
// visibleJS is a javascript snippet that returns true or false depending
// on if the specified node's offsetParent is not null.