mirror of
https://github.com/MontFerret/ferret.git
synced 2025-11-23 21:54:45 +02:00
Added errors to ClickX methods and added existence check (#341)
* Added errors to ClickX methods and added existence check * Fixes * Return None from Iterator when an error occurs
This commit is contained in:
@@ -26,7 +26,7 @@ func Click(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
return el.Click(ctx)
|
||||
return values.True, el.Click(ctx)
|
||||
}
|
||||
|
||||
// CLICK(doc, selector)
|
||||
@@ -36,7 +36,16 @@ func Click(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
selector := args[1].String()
|
||||
selector := values.ToString(args[1])
|
||||
exists, err := doc.ExistsBySelector(ctx, selector)
|
||||
|
||||
return doc.ClickBySelector(ctx, values.NewString(selector))
|
||||
if err != nil {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
if !exists {
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
return exists, doc.ClickBySelector(ctx, selector)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,17 @@ func ClickAll(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
selector := args[1].String()
|
||||
selector := values.ToString(args[1])
|
||||
|
||||
return doc.ClickBySelectorAll(ctx, values.NewString(selector))
|
||||
exists, err := doc.ExistsBySelector(ctx, selector)
|
||||
|
||||
if err != nil {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
if !exists {
|
||||
return values.False, nil
|
||||
}
|
||||
|
||||
return values.True, doc.ClickBySelectorAll(ctx, selector)
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ func ElementExists(ctx context.Context, args ...core.Value) (core.Value, error)
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
return el.ExistsBySelector(ctx, selector), nil
|
||||
return el.ExistsBySelector(ctx, selector)
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ func Input(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
selector := values.ToString(arg2)
|
||||
delay := values.Int(0)
|
||||
|
||||
if len(args) == 4 {
|
||||
@@ -55,10 +56,20 @@ func Input(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
delay = arg4.(values.Int)
|
||||
delay = values.ToInt(arg4)
|
||||
}
|
||||
|
||||
return doc.InputBySelector(ctx, arg2.(values.String), args[2], delay)
|
||||
exists, err := doc.ExistsBySelector(ctx, selector)
|
||||
|
||||
if err != nil {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
if !exists {
|
||||
return values.False, nil
|
||||
}
|
||||
|
||||
return values.True, doc.InputBySelector(ctx, selector, args[2], delay)
|
||||
}
|
||||
|
||||
el, err := drivers.ToElement(arg1)
|
||||
|
||||
@@ -92,11 +92,17 @@ func (i *PagingIterator) Next(ctx context.Context) (core.Value, core.Value, erro
|
||||
return values.ZeroInt, values.ZeroInt, nil
|
||||
}
|
||||
|
||||
if !i.document.ExistsBySelector(ctx, i.selector) {
|
||||
return values.ZeroInt, values.ZeroInt, core.ErrNoMoreData
|
||||
exists, err := i.document.ExistsBySelector(ctx, i.selector)
|
||||
|
||||
if err != nil {
|
||||
return values.None, values.None, err
|
||||
}
|
||||
|
||||
_, err := i.document.ClickBySelector(ctx, i.selector)
|
||||
if !exists {
|
||||
return values.None, values.None, core.ErrNoMoreData
|
||||
}
|
||||
|
||||
err = i.document.ClickBySelector(ctx, i.selector)
|
||||
|
||||
if err != nil {
|
||||
return values.None, values.None, err
|
||||
|
||||
Reference in New Issue
Block a user