mirror of
https://github.com/MontFerret/ferret.git
synced 2025-11-06 08:39:09 +02:00
Bugfix/inner text html by selector (#347)
* Fixed inner text * Fixed inner html * Updated set inner html and inner text * Changed mechanism of reading and writing inner text and html * updated makefile * Added e2e tests * Updated makefile * Updated changelog * Reverted dynamic page example
This commit is contained in:
@@ -727,7 +727,22 @@ func (el *HTMLElement) GetInnerTextBySelector(ctx context.Context, selector valu
|
||||
return values.EmptyString, drivers.ErrDetached
|
||||
}
|
||||
|
||||
out, err := el.exec.EvalWithReturnValue(ctx, templates.GetInnerTextBySelector(selector.String()))
|
||||
sel, err := selector.MarshalJSON()
|
||||
|
||||
if err != nil {
|
||||
return values.EmptyString, err
|
||||
}
|
||||
|
||||
out, err := el.exec.EvalWithArgumentsAndReturnValue(
|
||||
ctx,
|
||||
templates.GetInnerTextBySelector(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return values.EmptyString, err
|
||||
@@ -741,7 +756,31 @@ func (el *HTMLElement) SetInnerTextBySelector(ctx context.Context, selector, inn
|
||||
return drivers.ErrDetached
|
||||
}
|
||||
|
||||
return el.exec.Eval(ctx, templates.SetInnerTextBySelector(selector.String(), innerText.String()))
|
||||
sel, err := selector.MarshalJSON()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val, err := innerText.MarshalJSON()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return el.exec.EvalWithArguments(
|
||||
ctx,
|
||||
templates.SetInnerTextBySelector(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: val,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (el *HTMLElement) GetInnerTextBySelectorAll(ctx context.Context, selector values.String) (*values.Array, error) {
|
||||
@@ -749,7 +788,22 @@ func (el *HTMLElement) GetInnerTextBySelectorAll(ctx context.Context, selector v
|
||||
return values.NewArray(0), drivers.ErrDetached
|
||||
}
|
||||
|
||||
out, err := el.exec.EvalWithReturnValue(ctx, templates.GetInnerTextBySelectorAll(selector.String()))
|
||||
sel, err := selector.MarshalJSON()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out, err := el.exec.EvalWithArgumentsAndReturnValue(
|
||||
ctx,
|
||||
templates.GetInnerTextBySelectorAll(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return values.NewArray(0), err
|
||||
@@ -793,7 +847,22 @@ func (el *HTMLElement) GetInnerHTMLBySelector(ctx context.Context, selector valu
|
||||
return values.EmptyString, drivers.ErrDetached
|
||||
}
|
||||
|
||||
out, err := el.exec.EvalWithReturnValue(ctx, templates.GetInnerHTMLBySelector(selector.String()))
|
||||
sel, err := selector.MarshalJSON()
|
||||
|
||||
if err != nil {
|
||||
return values.EmptyString, err
|
||||
}
|
||||
|
||||
out, err := el.exec.EvalWithArgumentsAndReturnValue(
|
||||
ctx,
|
||||
templates.GetInnerHTMLBySelector(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return values.EmptyString, err
|
||||
@@ -807,7 +876,31 @@ func (el *HTMLElement) SetInnerHTMLBySelector(ctx context.Context, selector, inn
|
||||
return drivers.ErrDetached
|
||||
}
|
||||
|
||||
return el.exec.Eval(ctx, templates.SetInnerHTMLBySelector(selector.String(), innerHTML.String()))
|
||||
sel, err := selector.MarshalJSON()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val, err := innerHTML.MarshalJSON()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return el.exec.EvalWithArguments(
|
||||
ctx,
|
||||
templates.SetInnerHTMLBySelector(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: val,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (el *HTMLElement) GetInnerHTMLBySelectorAll(ctx context.Context, selector values.String) (*values.Array, error) {
|
||||
@@ -815,7 +908,22 @@ func (el *HTMLElement) GetInnerHTMLBySelectorAll(ctx context.Context, selector v
|
||||
return values.NewArray(0), drivers.ErrDetached
|
||||
}
|
||||
|
||||
out, err := el.exec.EvalWithReturnValue(ctx, templates.GetInnerHTMLBySelectorAll(selector.String()))
|
||||
sel, err := selector.MarshalJSON()
|
||||
|
||||
if err != nil {
|
||||
return values.NewArray(0), err
|
||||
}
|
||||
|
||||
out, err := el.exec.EvalWithArgumentsAndReturnValue(
|
||||
ctx,
|
||||
templates.GetInnerHTMLBySelectorAll(),
|
||||
runtime.CallArgument{
|
||||
ObjectID: &el.id.objectID,
|
||||
},
|
||||
runtime.CallArgument{
|
||||
Value: sel,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return values.NewArray(0), err
|
||||
|
||||
@@ -5,28 +5,36 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/drivers"
|
||||
)
|
||||
|
||||
func GetInnerHTMLBySelector(selector string) string {
|
||||
return fmt.Sprintf(`
|
||||
const selector = "%s";
|
||||
const found = document.querySelector(selector);
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
var getInnerHTMLBySelectorTemplate = fmt.Sprintf(`
|
||||
(el, selector) => {
|
||||
const found = el.querySelector(selector);
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
}
|
||||
|
||||
return found.innerHTML;
|
||||
}
|
||||
`, drivers.ErrNotFound,
|
||||
)
|
||||
|
||||
return found.innerHTML;
|
||||
`, selector, drivers.ErrNotFound)
|
||||
func GetInnerHTMLBySelector() string {
|
||||
return getInnerHTMLBySelectorTemplate
|
||||
}
|
||||
|
||||
func GetInnerHTMLBySelectorAll(selector string) string {
|
||||
return fmt.Sprintf(`
|
||||
const selector = "%s";
|
||||
const found = document.querySelectorAll(selector);
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
var getInnerHTMLBySelectorAllTemplate = fmt.Sprintf(`
|
||||
(el, selector) => {
|
||||
const found = el.querySelectorAll(selector);
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
}
|
||||
|
||||
return Array.from(found).map(i => i.innerHTML);
|
||||
}
|
||||
`, drivers.ErrNotFound,
|
||||
)
|
||||
|
||||
return Array.from(found).map(i => i.innerHTML);
|
||||
`, selector, drivers.ErrNotFound)
|
||||
func GetInnerHTMLBySelectorAll() string {
|
||||
return getInnerHTMLBySelectorAllTemplate
|
||||
}
|
||||
|
||||
@@ -5,28 +5,36 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/drivers"
|
||||
)
|
||||
|
||||
func GetInnerTextBySelector(selector string) string {
|
||||
return fmt.Sprintf(`
|
||||
const selector = "%s";
|
||||
const found = document.querySelector(selector);
|
||||
var getInnerTextBySelectorTemplate = fmt.Sprintf(`
|
||||
(el, selector) => {
|
||||
const found = el.querySelector(selector);
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
throw new Error("%s");
|
||||
}
|
||||
|
||||
return found.innerText;
|
||||
`, selector, drivers.ErrNotFound)
|
||||
}
|
||||
`, drivers.ErrNotFound,
|
||||
)
|
||||
|
||||
func GetInnerTextBySelector() string {
|
||||
return getInnerTextBySelectorTemplate
|
||||
}
|
||||
|
||||
func GetInnerTextBySelectorAll(selector string) string {
|
||||
return fmt.Sprintf(`
|
||||
const selector = "%s";
|
||||
const found = document.querySelectorAll(selector);
|
||||
var getInnerTextBySelectorAllTemplate = fmt.Sprintf(`
|
||||
(el, selector) => {
|
||||
const found = el.querySelectorAll(selector);
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
throw new Error("%s");
|
||||
}
|
||||
|
||||
return Array.from(found).map(i => i.innerText);
|
||||
`, selector, drivers.ErrNotFound)
|
||||
}
|
||||
`, drivers.ErrNotFound,
|
||||
)
|
||||
|
||||
func GetInnerTextBySelectorAll() string {
|
||||
return getInnerTextBySelectorAllTemplate
|
||||
}
|
||||
|
||||
@@ -15,19 +15,20 @@ func SetInnerHTML() string {
|
||||
return setInnerHTMLTemplate
|
||||
}
|
||||
|
||||
func SetInnerHTMLBySelector(selector, innerHTML string) string {
|
||||
return fmt.Sprintf(`
|
||||
const selector = "%s";
|
||||
const found = document.querySelector(selector)
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
var setInnerHTMLBySelectorTemplate = fmt.Sprintf(`
|
||||
(el, selector, value) => {
|
||||
const found = el.querySelector(selector);
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
}
|
||||
|
||||
found.innerHTML = value;
|
||||
}
|
||||
|
||||
found.innerHTML = "%s"
|
||||
`,
|
||||
selector,
|
||||
drivers.ErrNotFound,
|
||||
innerHTML,
|
||||
)
|
||||
drivers.ErrNotFound,
|
||||
)
|
||||
|
||||
func SetInnerHTMLBySelector() string {
|
||||
return setInnerHTMLBySelectorTemplate
|
||||
}
|
||||
|
||||
@@ -15,19 +15,20 @@ func SetInnerText() string {
|
||||
return setInnerTextTemplate
|
||||
}
|
||||
|
||||
func SetInnerTextBySelector(selector, innerText string) string {
|
||||
return fmt.Sprintf(`
|
||||
const selector = "%s";
|
||||
const found = document.querySelector(selector)
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
var setInnerTextBySelectorTemplate = fmt.Sprintf(`
|
||||
(el, selector, value) => {
|
||||
const found = el.querySelector(selector);
|
||||
|
||||
if (found == null) {
|
||||
throw new Error('%s');
|
||||
}
|
||||
|
||||
found.innerText = value;
|
||||
}
|
||||
|
||||
found.innerText = "%s"
|
||||
`,
|
||||
selector,
|
||||
drivers.ErrNotFound,
|
||||
innerText,
|
||||
)
|
||||
drivers.ErrNotFound,
|
||||
)
|
||||
|
||||
func SetInnerTextBySelector() string {
|
||||
return setInnerTextBySelectorTemplate
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user