Getting Unable to cast COM object of type 'System.__ComObject' to interface type while trying to click on a button

0

I want to call click event of a button from a web page by using my client c# code.

I can see the element as after doing F12 on the page as:

<button class="btn btn-primary form-control btn-block" type="button" 
  ng-click="tranCtrl.retrieveTransactionsList('Go')" ng-disabled="tranCtrl.isLoading">
   Go 
</button>

My code works for all the input type buttons but not for the above one.

I have tried multiple classes like IHTMLButtonElement but it's not allowing casting of the _comObject returned for the button to the HTMLElement class. It throws invalid cast exception every time.

Ex : Unable to cast COM object of type 'System.__ComObject' to interface type 
'mshtml.HTMLButtonElement'. This operation failed because the QueryInterface 
call on the COM component for the interface with IID '{3050F51F-98B5-11CF-BB82-
00AA00BDCE0B}' failed due to the following error: No such interface supported 
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

To download button from web page :

IHTMLDocument3 myHTMLDoc3;

myHTMLDoc3 = this.Browser != null ? (IHTMLDocument3)this.Browser.Document : null;
if(myHTMLDoc3!=null)
{
    var buttons = myHTMLDoc3.getElementsByTagName("Button");
    return buttons;
}

Below is the typecasting code throwing error :

if (objControlElement.GetType().Name == "HTMLInputElement")
{
    htmlInputElement = objControlElement != null ? 
    (HTMLInputElement)objControlElement : null;
    if (htmlInputElement != null)
    {
        htmlInputElement.click();
        executionStatus = true;
    }
}

I can see the element as after doing F12 on the page as:

<button class="btn btn-primary form-control btn-block" type="button" 
 ng-click="tranCtrl.retrieveTransactionsList('Go')" ng-
 disabled="tranCtrl.isLoading">Go </button>
c#
angularjs
com-interop
asked on Stack Overflow Apr 26, 2019 by Nitin • edited Apr 26, 2019 by Hasta Tamang

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0