I've been wondering whether or not this is possible -
Here is a picture of Chrome's "inspect element" on this website. enter image description here
Is it possible for me to run the "goCourseDetails" js function with my own parameters?
I'm using Python and selenium to try and write a script that does that for me, but I don't know how to access the JS function.
Thanks in advance.
1 Answer 1
You can use driver.execute_script() to execute javascript snippet in browser.
The function goCourseDetails can be obtain from browser global variable window
driver.execute_script('window.goCourseDetails.call(null, arguments)',
<department>, <degreelevel>, <course>, <detail>, <year>, <semester>
)
answered Sep 7, 2018 at 5:13
yong
13.8k1 gold badge19 silver badges27 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
Barak B
Hey, this looks like a nice solution, however when I'm doing this, I run into
Cannot set property 'target' of undefined (so document.mainForm is probably null) is there a way to get over this?Barak B
The idea is that there's a button, that on click runs
<a href="javascript:goCourseDetails('201','1','2391','1','2019','1')">Clickme</a> and I can't access the actual element <a>, and so I want to be able to "click" it, or run the function that it runs when clicked.yong
Can you succeed to execute
goCourseDetails('201','1','2391','1','2019','1') in browser' console in Developer Tool.Barak B
I can run it on F12 -> Console, if that's what you meant. How does this help though?
Barak B
Apparently I've done something wrong causing target to be undefined, it's working now, thanks!
default
undefinedand so this cannot be run like that. Any ideas?