2016-07-13 38 views
0

我只想單擊按鈕或編輯輸入的文本,但我無法使用此方法執行此操作。我將這些元素存儲在公共靜態類中,然後從另一個公共靜態類中調用它們。如果我不使用這個類,我不會例外。TypeInitializationException在使用c#中的元素執行操作時,Selenium

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

    } 
} 

類型「System.TypeInitializationException」的未處理的異常發生在MyExeName.exe

其他信息:爲「輸入」的類型初始引發了異常。

內部異常包含此消息:

無法定位元件:{ 「方法」: 「ID」, 「選擇器」: 「some_element」}

另一個細節(我認爲可能有必要):

類型名:輸入

回答

0

問題出在static參數。

相關問題