Получение Невозможно привести объект COM типа 'System .__ ComObject' к типу интерфейса при попытке нажать на кнопку - PullRequest
0 голосов
/ 26 апреля 2019

Я хочу вызвать событие нажатия кнопки на веб-странице, используя мой клиентский код c #.

Я могу видеть элемент после F12 на странице как:

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

Мой код работает для всех кнопок типа ввода, но не для вышеупомянутой.

Я пробовал несколько классов, таких как IHTMLButtonElement, но он не разрешает приведение _comObject, возвращенного для кнопки в HTMLElement класс.Выдает invalid cast exception каждый раз.

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))

Для загрузки кнопки с веб-страницы:

IHTMLDocument3 myHTMLDoc3;

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

Ниже приведена ошибка при подборе кода при типизации:

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

Я могу видеть элемент как после F12 на странице как:

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