2016-11-11 69 views
2
public MainWindow() 
{ 
    InitializeComponent(); 

    BrowserView webView = new WPFBrowserView(); 
    mainLayout.Children.Add((UIElement)webView.GetComponent()); 
    ManualResetEvent waitEvent = new ManualResetEvent(false); 
    webView.Browser.FinishLoadingFrameEvent += delegate (object sender, FinishLoadingEventArgs e) 
    { 
     if (e.IsMainFrame) 
     { 
      waitEvent.Set(); 
     } 
    }; 
    webView.Browser.LoadURL("https://console.api.ai/api-client/#/login"); 
    waitEvent.WaitOne(); 
    DOMDocument document = webView.Browser.GetDocument(); 
    DOMElement username = document.GetElementById("username"); 
    username.SetAttribute("value", "[email protected]"); 
} 

這是我的程序導航到「https://console.api.ai/api-client/#/login」。如何使用DotNetBrowser填寫用戶名和密碼

我試圖使用.SetAttribute將「[email protected]」填充到網站的電子郵件文本框中,但它不起作用。

任何人都知道如何解決這個問題?

謝謝!

回答

0

在提供的示例代碼中,您嘗試通過元素屬性修改元素屬性。元素的屬性不能用於修改元素的屬性:What is the difference between properties and attributes in HTML?

下面是一個說明如何使用Value屬性用於設置輸入字段值的示例代碼:

DOMInputElement username = (DOMInputElement)document.GetElementById("username"); 
username.Value = "[email protected]"; 

由下面的鏈接的示例演示瞭如何與各種表單域一起工作: https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110038-setting-input-field-value-working-with-form