C#trouble webbrowser onclick elementid

时间:2011-06-07 19:34:02

标签: c# browser

我要做的是使用C#http://www.madisonhonda.com/Preowned-Inventory.aspx?layout=layout1#

抓取此网页

到目前为止我所拥有的是

public const string TestURL = "http://www.madisonhonda.com/PreownedInventory.aspx#layout=layout1";
static void kickOFF()
{
    WebBrowser wb = new WebBrowser();

    //wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
    wb.Navigate(TestURL);
    while (wb.ReadyState != WebBrowserReadyState.Complete)
    {
        Application.DoEvents();
    }

    HtmlElement document = wb.Document.GetElementsByTagName("html")[0];
    HtmlElement button = wb.Document.GetElementById("ctl08_ctl00_InventoryListDisplayFieldRepeater2_ctl00_BlockViewPaging_Next");
    button.InvokeMember("click");

使用firebug这就是我要点击的元素如下所示:

a id="ctl08_ctl00_InventoryListDisplayFieldRepeater2_ctl00_BlockViewPaging_Next"       
href="Default.aspx?ajax_callback=true&ajax_t=1307474539641&hyperlinkargument=Next&page=preowned-inventory&previouspage=1&totalrecords=83&currentpage=Next&layout=layout1&pagesize=25&virtualpageindex=0&numberofvisiblepages=10" 
savedhref="Default.aspx?ajax_callback=true&ajax_t=1307474539641&hyperlinkargument=Next&page=preowned-inventory&previouspage=1&totalrecords=83&currentpage=Next&layout=layout1&pagesize=25&virtualpageindex=0&numberofvisiblepages=10" 
onclick="javascript:AJAX_FireCallBackEvent(this,event,'ctl08$ctl00$InventoryListDisplayFieldRepeater2$ctl00$BlockViewPaging$Next','$Next',true,'','','',true,PreSearchAjax,PostSearchAjax,null,true,true);return false;"> ► </a>

我误读了身份证吗?不是吗? ctl08_ctl00_InventoryListDisplayFieldRepeater2_ctl00_BlockViewPaging_Next

另外,每次进行InvokeMember时,如何重新加载html?

好的,所以更新如果我在winform中添加一个按钮,它会循环扔掉网页。

1 个答案:

答案 0 :(得分:0)

是否必须使用托管的WinForms WebBrowser控件完成?

如果您可以通过普通浏览器执行所需操作,我建议您使用专用的Web测试框架(如Selenium或Watin)来执行此级别的自动化,而不是尝试让WebBrowser控件执行此操作。