Running JavaScript (Eval, MustEval) #354
Answered
by
MikhailKlemin
MikhailKlemin
asked this question in
Q&A
-
Hello! I am not sure I understand how to run a custom JS script. The script works fine in chrome console, but does nothing when I try to run it via page.MustEval() on same page. Do I miss something obvious? var js = `myevent = $.Event('mousedown');
elem = $('.uclw_noUi-base');
pos = elem.offset().left;
myevent.clientX = pos;
myevent.clientY = 0;
elem.trigger(myevent);`
err := rod.Try(func() {
page.MustSearch(".uclw_noUi-base").WaitStable(2 * time.Second)
page.MustEval(js)
if err != nil {
log.Fatal(err)
}
page.WaitLoad()
})
if err!=nil{
log.Fatal(err)
} |
Beta Was this translation helpful? Give feedback.
Answered by
MikhailKlemin
Feb 17, 2021
Replies: 2 comments 1 reply
-
Well, I understand you can't execute such JavaScript, albeit it was possible on ChromeDP. left := page.MustEval("$('.uclw_noUi-base').offset().left").Int()
top := page.MustEval("$('.uclw_noUi-base').offset().top").Int()
mouse := page.Mouse
mouse.Move(float64(left), float64(top), 2)
mouse.MustDown(proto.InputMouseButtonLeft)
mouse.MustUp(proto.InputMouseButtonLeft) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
MikhailKlemin
-
The js block works fine for me, not sure how to reproduce your problem. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, I understand you can't execute such JavaScript, albeit it was possible on ChromeDP.
I have rewrote it, works as intended :-)