Skip to content

Commit

Permalink
Fixed element not found error (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex authored Jan 17, 2022
1 parent 64f086a commit 8d8afed
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
8 changes: 8 additions & 0 deletions e2e/tests/dynamic/element/query/element_not_found_by_css.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LET url = @lab.cdn.dynamic
LET doc = DOCUMENT(url, { driver: "cdp" })

LET el = ELEMENT(doc, "#do-not-exist")

T::NONE(el)

RETURN TRUE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LET url = @lab.cdn.dynamic
LET doc = DOCUMENT(url, true)

LET el = ELEMENT(doc, X("//*[@id='do-not-exist']"))?

T::NONE(el)

RETURN TRUE
8 changes: 8 additions & 0 deletions e2e/tests/dynamic/element/siblings/next_not_found.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LET doc = DOCUMENT(@lab.cdn.dynamic + "/#/lists", { driver:"cdp" })

LET current = ELEMENT(doc, "body")
T::NOT::NONE(current)
LET next = current.nextElementSibling
T::NONE(next)

RETURN NONE
8 changes: 8 additions & 0 deletions e2e/tests/dynamic/element/siblings/prev_not_found.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LET doc = DOCUMENT(@lab.cdn.dynamic + "/#/lists", { driver:"cdp" })

LET current = ELEMENT(doc, 'head')
T::NOT::NONE(current)
LET prev = current.previousElementSibling
T::NONE(prev)

RETURN NONE
6 changes: 5 additions & 1 deletion pkg/drivers/cdp/eval/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ func (rt *Runtime) EvalValue(ctx context.Context, fn *Function) (core.Value, err
return rt.resolver.ToValue(ctx, out)
}

func (rt *Runtime) EvalElement(ctx context.Context, fn *Function) (drivers.HTMLElement, error) {
func (rt *Runtime) EvalElement(ctx context.Context, fn *Function) (core.Value, error) {
ref, err := rt.EvalRef(ctx, fn)

if err != nil {
return nil, err
}

if ref.ObjectID == nil {
return values.None, nil
}

return rt.resolver.ToElement(ctx, ref)
}

Expand Down
12 changes: 3 additions & 9 deletions pkg/drivers/cdp/templates/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,21 @@ const (
)

var (
queryCSSSelector = fmt.Sprintf(`
queryCSSSelector = `
(el, selector) => {
const found = el.querySelector(selector);
%s
return found;
}
`,
notFoundErrorFragment,
)
`
queryXPathSelector = fmt.Sprintf(`
(el, selector) => {
%s
%s
return found;
}
`,
xpathAsElementFragment, notFoundErrorFragment,
xpathAsElementFragment,
)
)

Expand Down

0 comments on commit 8d8afed

Please sign in to comment.