1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Calling javascript functions from C# 2008

Discussion in 'C#' started by endoExpert, Aug 28, 2010.

  1. endoExpert

    endoExpert New Member

    Aug 28, 2010
    Likes Received:
    Trophy Points:
    I have this code in a C# application that is automating a Web app. I want to execute the javascript function and would like to SEE the results, however when running the app I get an exception "Specified cast is not valid." on line 2 below.

    mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)ie.Document;
    mshtml.IHTMLWindow2 parentWin = doc2.parentWindow;
    parentWin.execScript("modifyQueryString(2)", "javascript");

    I have seen a dozen very old (2005) versions of solutions to this, and this is one I have tried. I am useing Visual Studion 2008, with SHDocVW.dll and mshtml.dll attached as resources.

Share This Page