2014-01-16 19 views
0

在WinForms中,我試圖使用一個非常簡單的WebBrowser控件用於雅虎郵件。我在vs2010中使用WebBrowser組件。首先,我加載一個頁面:無法點擊使用.NET WebBrowser控件的yahoo郵件中的複選框

webBrowser1.Url = new Uri("http://mail.yahoo.com"); 

然後我試圖在我的電子郵件,以選擇所有項目:

private void btnSelectAll_Click(object sender, EventArgs e) 
{ 
    // Select checkboxes containing the word "this" (Select this email) 
    foreach (HtmlElement oCheckBox in webBrowser1.Document.GetElementsByTagName("input")) 
    { 
    if (oCheckBox.GetAttribute("type").ToLower() == "checkbox") 
    { 
     if (oCheckBox.OuterHtml.ToLower().Contains("this")) 
     { 
     //oCheckBox.SetAttribute("value", "Yes"); //did not work 
     //oCheckBox.SetAttribute("value", "1"); //did not work 
     //oCheckBox.InvokeMember("Click");   //did not work 
     oCheckBox.InvokeMember("CLICK");   //did not work 
     } 
    } 
    } 
} 

嘗試了上述所有的和他們沒有選擇複選框。不確定是否特定於雅虎郵箱中的複選框是如何設置的?任何幫助,將不勝感激。

感謝前手

+0

使用您的開發工具,以檢查什麼樣的,他們有什麼樣的元素, – SLaks

+0

類型元素是「複選框」時,就執行「 ..InvokeMember(「CLICK」)..「它只是不選中複選框。 – user3062349

回答

0

解決方案:

private void btnSelectAll_Click(object sender, EventArgs e) 
{ 
    // Select checkboxes containing the word "this" (Select this email) 
    foreach (HtmlElement oCheckBox in webBrowser1.Document.GetElementsByTagName("input")) 
    { 
    if (oCheckBox.GetAttribute("type").ToLower() == "checkbox") 
    { 
     if (oCheckBox.OuterHtml.ToLower().Contains("this")) 
     { 
     oCheckBox.SetAttribute("checked", "true"); 
     } 
    } 
    } 
}