C# trouble webbrowser onclick elementid

北城以北 提交于 2019-12-24 06:44:51

问题


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

    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.


回答1:


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.



来源:https://stackoverflow.com/questions/6270606/c-sharp-trouble-webbrowser-onclick-elementid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!