Executing Javascript function in a web page in IE

The following code executes a Javascript function on a web page using IE and COM.

import win32com.client, pythoncom
from time import sleep

sleep(5) # Give it time to get there.

id=ie.Document.Script._oleobj_.GetIDsOfNames('Multiply') # 'Multiply' is the function name.
#5 and 2 below are the parameters passed to the function 'Multiply'.
res=ie.Document.Script._oleobj_.Invoke(id, 0, pythoncom.DISPATCH_METHOD, True, 5, 2)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.