简体   繁体   中英

InvokeMember(“Click”) Web Browser control error C# WPF

I am getting this error when running my code.

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.MarshalByRefObject.InvokeMember(string, System.Reflection.BindingFlags, System.Reflection.Binder, object[], System.Reflection.ParameterModifier[], System.Globalization.CultureInfo, string[])' is inaccessible due to its protection level'

I see that when clicking the button it is finding the correct button name but it is not clicking it. Below is my full code.

//LOGIN 
    private void Login_Click(object sender, RoutedEventArgs e)
    {
        dynamic d = wb.Document;
        var el = d.GetElementsByTagName("input");
        var button = d.GetElementsByTagName("button");

        d.GetElementsByname("login")[0].value = this.NameBox.Text;
        d.GetElementsByName("password")[0].value = this.PWBox.Text;
        d.GetElementsByname("save")[0].InvokeMember("login");enter code here

    }

This is the button code

<buttons>
        <button name="save" class="k-btn-dark" type="submit">Login</button>

The Password and Username fields generate correctly but I get the "inaccessible" error on button click.

Isn't it a problem of class accessibility ? or function ?

Look at this post which talks about Resources but it could be the same for your case: 'Resource' is inaccessible due to its protection level

I GOT IT!

d.GetElementsByName("save")[0].Click();

No need for the InvokeMember.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM