开发者

C# trouble webbrowser onclick elementid

What i'm trying to do is crawl this webpage using C# http://www.madisonhonda.com/Preowned-Inventory.aspx?layout=layout1#

What I have so far is this

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();
    开发者_JS百科}

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

Using firebug this is what it says for the element I want to click is the following:

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>

Am I misreading the ID? Is it not? ctl08_ctl00_InventoryListDisplayFieldRepeater2_ctl00_BlockViewPaging_Next

Also, how would I reload the html for each time I do an InvokeMember?

Okay, so update if i add a button to my winform it will cycle threw the webpages.


Does it have to be done using the hosted WinForms WebBrowser control?

If you can do what ever you need through a normal browser I would suggest you use a dedicated web testing framework such as Selenium or Watin to perform this level of automation rather than trying to get the WebBrowser control to do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜