当使用c#,Selenium中的元素执行操作时,TypeInitializationException [英] TypeInitializationException when doing action with an element in c#, Selenium
问题描述
我只想点击一个按钮,或编辑一个输入的文本,但是我不能用这种方法。我将这些元素存储在一个公共静态类中,我从另一个公共静态类中调用它们。如果我不使用这个类,我没有得到例外。
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();
}
}
在MyExeName.exe中发生类型为System.TypeInitializationException的未处理异常
An unhandled exception of type 'System.TypeInitializationException' occurred in MyExeName.exe
附加信息:输入的类型初始化程序抛出异常。
Additional information: The type initializer for 'Input' threw an exception.
内部异常包含此消息:
无法找到元素:{method:id,selector:some_element}
Unable to locate element: {"method":"id","selector":"some_element"}
另一个细节(我认为这是必要的):
Another detail (I think it can be necessary):
TypeName:Input
TypeName: Input
推荐答案
问题出在 static
参数。
这篇关于当使用c#,Selenium中的元素执行操作时,TypeInitializationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!