Adding ElementNotPresent/WaitNotPresent query option/action
This commit is contained in:
parent
6769aefc5e
commit
6eec61e7df
|
@ -48,6 +48,7 @@ func submit(urlstr, sel, q string, res *string) cdp.Tasks {
|
||||||
cdp.WaitVisible(sel),
|
cdp.WaitVisible(sel),
|
||||||
cdp.SendKeys(sel, q),
|
cdp.SendKeys(sel, q),
|
||||||
cdp.Submit(sel),
|
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),
|
cdp.Text(`//*[@id="js-pjax-container"]/div[2]/div/div[2]/ul/li/p`, res),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
sel.go
18
sel.go
|
@ -27,6 +27,7 @@ tagname
|
||||||
// Error types.
|
// Error types.
|
||||||
var (
|
var (
|
||||||
ErrNoResults = errors.New("no results")
|
ErrNoResults = errors.New("no results")
|
||||||
|
ErrHasResults = errors.New("has results")
|
||||||
ErrNotVisible = errors.New("not visible")
|
ErrNotVisible = errors.New("not visible")
|
||||||
ErrVisible = errors.New("visible")
|
ErrVisible = errors.New("visible")
|
||||||
ErrDisabled = errors.New("disabled")
|
ErrDisabled = errors.New("disabled")
|
||||||
|
@ -483,6 +484,18 @@ func ElementSelected(s *Selector) {
|
||||||
}))(s)
|
}))(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
|
// AtLeast is a query option to wait until at least n elements are returned
|
||||||
// from the query selector.
|
// from the query selector.
|
||||||
func AtLeast(n int) QueryOption {
|
func AtLeast(n int) QueryOption {
|
||||||
|
@ -525,6 +538,11 @@ func WaitSelected(sel interface{}, opts ...QueryOption) Action {
|
||||||
return Query(sel, append(opts, ElementSelected)...)
|
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 (
|
const (
|
||||||
// visibleJS is a javascript snippet that returns true or false depending
|
// visibleJS is a javascript snippet that returns true or false depending
|
||||||
// on if the specified node's offsetParent is not null.
|
// on if the specified node's offsetParent is not null.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user