Calling javascript functions from C# 2008

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

  1. endoExpert

    endoExpert New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice