Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我可以在mshtml.IHTMLElement.click()调用中检测到失败吗?_C#_Click_Webbrowser Control_Mshtml - Fatal编程技术网

C# 我可以在mshtml.IHTMLElement.click()调用中检测到失败吗?

C# 我可以在mshtml.IHTMLElement.click()调用中检测到失败吗?,c#,click,webbrowser-control,mshtml,C#,Click,Webbrowser Control,Mshtml,我能否确定呼叫是否成功?我正在调试一个点击按钮的应用程序(见下面的代码),有时它似乎无法做到这一点,我想确定点击是否成功 HtmlElement button = ...; IHTMLElement nativeElement = button.DomElement as IHTMLElement; nativeElement.click(); 您是否考虑过为该特定HTMLElement的click事件添加事件处理程序?您可以按照以下思路做一些事情: bool shouldfire =

我能否确定呼叫是否成功?我正在调试一个点击按钮的应用程序(见下面的代码),有时它似乎无法做到这一点,我想确定点击是否成功

HtmlElement button = ...;
IHTMLElement nativeElement = button.DomElement as IHTMLElement;
nativeElement.click();

您是否考虑过为该特定HTMLElement的click事件添加事件处理程序?您可以按照以下思路做一些事情:

    bool shouldfire = false;
    bool didFire = false;
    private void yourMethod()
    { 
        HtmlElement button = ...; //however you are getting this element
        button.Click +=button_Click;
        IHTMLElement nativeElement = button.DomElement as IHTMLElement;
        nativeElement.click();
        shouldfire = true;
    } 
    private void button_Click(object sender, HtmlElementEventArgs e)
    {
        didFire = true;
    }
    private void yourOtherMethod()
    {
        if (shouldfire != didFire)
        { 
            //do something
        }

    }

你能定义什么是成功吗?我不知道你的意思,我会告诉你用一个try-catch来包装它;)无论按钮是否被点击,因为有时(我正在调试应用程序)它似乎不是。在这种情况下,它没有引发异常(按钮被找到,只是似乎没有触发的事件)。