TypeInitializationException when doing action with an element in c#, Selenium

一笑奈何 提交于 2019-12-25 07:39:11

问题


I just want to click a button, or edit an input's text, but I can't do it with this method. I'm storing the elements in a public static class, and I call them from an another public static class. If I don't use this classes, i don't get exception.

public static class SiteA
{
    static uidriver = Program.uidriver;

    public static class Functionality
    {
        public static void SomeTest()
        {
            //...
            Inputs.Buttons.Authorize.Click(); //Here I get the exception
            //Working code: uidriver.FindElement(By.Id("some_element")).Click();
            //...
        }
    }

    public static class Inputs
    {
        public static class Buttons
        {
            public static IWebElement Authorize = uidriver.FindElement(By.Id("some_element"));
        }
    }   
}

class Program
{
    public static IWebDriver uidriver;
    static void Main(string[] args)
    {
        uidriver = new FirefoxDriver();

        SiteA.Functionality.SomeTest();

    }
}

An unhandled exception of type 'System.TypeInitializationException' occurred in MyExeName.exe

Additional information: The type initializer for 'Input' threw an exception.

The inner exception contains this message:

Unable to locate element: {"method":"id","selector":"some_element"}

Another detail (I think it can be necessary):

TypeName: Input


回答1:


The problem was with the static parameter.



来源:https://stackoverflow.com/questions/38353488/typeinitializationexception-when-doing-action-with-an-element-in-c-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!