I'm developing an application that performs automation in internet explorer, I'm using SHDocVw to do this.
My problem is that I can not get the feedback from a JavaScript injection
public static void wJScript(string script) {
try {
Thread th = new Thread(ExecuteJavaScriptWorker);
th.SetApartmentState(ApartmentState.STA);
th.Start(script);
}
catch (Exception) {
throw;
}
}
private static void ExecuteJavaScriptWorker(object script) {
try {
IHTMLDocument2 document = IE.Document;
object resp = document.parentWindow.execScript(script.ToString(), "JScript");
Console.Write(resp);
}
catch (Exception) {
throw;
}
}
My resp variable always returns null
The variable script
can get any JavaScript command from a simple document.getElementById('id').value
to even call a function that I have on the page:
Let's say I have the following function on my page:
function soma(a,b) {
return a + b;
}
And pass as a parameter to my function wJScript("soma(1,2)")
it should return the result of the function, but this does not happen!