0

I have some code that has been working for me for several months, but today, I am getting casting errors?

I am using the mshtml library to click an adjust input image:

mshtml.IHTMLElementCollection objCollection = (mshtml.IHTMLElementCollection)objDocument.getElementsByName("submit");
for (int i = 0; i < objCollection.length; i++)
{
   mshtml.IHTMLElement objElement = (mshtml.IHTMLElement)objCollection.item(i, 0);
   if (objElement.getAttribute("alt") == "adjust")
   {
      // This line below gives me the error.
      mshtml.htmlInputImage objSubmit = (mshtml.htmlInputImage)objElement;
      objSubmit.click();
      bOK = true;
   }
}

At the // line above, I get the following message:

Unable to cast object of type 'mshtml.HTMLInputElementClass' to type 'mshtml.htmlInputImage'.

This used to work and this part of the code has not changed. Does anyone know what I might be doing wrong and why should this just start to not work? I use this type of structure in other places and all is working...

Brandon
  • 645
  • 5
  • 13
QuietLeni
  • 139
  • 1
  • 3
  • 12
  • Has the the mark-up for the page changed? – Brandon Apr 29 '14 at 22:32
  • As far as I know, the page has not changed, but that is the sort of thing that I was wondering. – QuietLeni Apr 30 '14 at 18:49
  • I think that the version of IE on the machine has been changed and his has broken things. I found another section of code and re-used that code that did almost the same thing and it is now working OK. – QuietLeni May 07 '14 at 19:52
  • You should post that as the answer and then accept it. Glad you found a solution to your problem. – Brandon May 07 '14 at 20:01

0 Answers0