html automation problem with c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brightlight
    New Member
    • Mar 2008
    • 5

    #1

    html automation problem with c#

    Hello
    I want to search for multiple barcodes in our local network. I am using C# and my problem is I can not build succesful Loops to search multiple barcodes. Since I need to wait for the page fully loaded none of my solutions worked.

    Here is the full code running against google web. I will be glad if you succeed to search for int ba=1 and loop it up to 10 with button click.




    using System;
    using System.Drawing;
    using System.Collecti ons;
    using System.Componen tModel;
    using System.Windows. Forms;
    using System.Data;
    using mshtml;

    namespace mshtml_automati on_demo
    {
    public class MainForm : System.Windows. Forms.Form
    {
    private AxSHDocVw.AxWeb Browser axWebBrowser1;
    private System.Windows. Forms.Button button1;
    private System.Componen tModel.Containe r components = null;

    public MainForm()
    {
    InitializeCompo nent();
    }

    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null)
    {
    components.Disp ose();
    }
    }
    base.Dispose( disposing );
    }

    #region Windows Form Designer generated code

    private void InitializeCompo nent()
    {
    System.Resource s.ResourceManag er resources = new System.Resource s.ResourceManag er(typeof(MainF orm));
    this.axWebBrows er1 = new AxSHDocVw.AxWeb Browser();
    this.button1 = new System.Windows. Forms.Button();
    ((System.Compon entModel.ISuppo rtInitialize)(t his.axWebBrowse r1)).BeginInit( );
    this.SuspendLay out();
    //
    // axWebBrowser1
    //
    this.axWebBrows er1.Dock = System.Windows. Forms.DockStyle .Fill;
    this.axWebBrows er1.Enabled = true;
    this.axWebBrows er1.Location = new System.Drawing. Point(0, 0);
    this.axWebBrows er1.OcxState = ((System.Window s.Forms.AxHost. State)(resource s.GetObject("ax WebBrowser1.Ocx State")));
    this.axWebBrows er1.Size = new System.Drawing. Size(616, 382);
    this.axWebBrows er1.TabIndex = 0;
    this.axWebBrows er1.Enter += new System.EventHan dler(this.axWeb Browser1_Enter) ;
    this.axWebBrows er1.DocumentCom plete += new AxSHDocVw.DWebB rowserEvents2_D ocumentComplete EventHandler(th is.axWebBrowser 1_DocumentCompl ete);
    //
    // button1
    //
    this.button1.Lo cation = new System.Drawing. Point(536, 8);
    this.button1.Na me = "button1";
    this.button1.Ta bIndex = 2;
    this.button1.Te xt = "button1";
    this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
    //
    // MainForm
    //
    this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
    this.ClientSize = new System.Drawing. Size(616, 382);
    this.Controls.A dd(this.button1 );
    this.Controls.A dd(this.axWebBr owser1);
    this.Name = "MainForm";
    this.Text = "Microsoft WebBrowser Automation";
    this.Load += new System.EventHan dler(this.FrmMa in_Load);
    ((System.Compon entModel.ISuppo rtInitialize)(t his.axWebBrowse r1)).EndInit();
    this.ResumeLayo ut(false);

    }
    #endregion


    [STAThread]
    static void Main()
    {
    Application.Run (new MainForm());
    }

    private void FrmMain_Load(ob ject sender, System.EventArg s e)
    {
    }

    private void axWebBrowser1_D ocumentComplete (object sender, AxSHDocVw.DWebB rowserEvents2_D ocumentComplete Event e)
    {
    int ba=1;

    HTMLDocument myDoc = new HTMLDocumentCla ss();
    myDoc = (HTMLDocument) axWebBrowser1.D ocument;
    HTMLInputElemen t otxtSearchBox = (HTMLInputEleme nt) myDoc.all.item( "q", 0);

    otxtSearchBox.v alue = ba.ToString(); /// searchin for ba loop needed
    otxtSearchBox.f ocus();
    SendKeys.Send(" {ENTER}");
    }

    private void axWebBrowser1_E nter(object sender, System.EventArg s e)
    {
    }

    private void button1_Click(o bject sender, System.EventArg s e)
    {
    object loc = "http://www.google.com" ;
    object null_obj_str = "";
    System.Object null_obj = 0;
    this.axWebBrows er1.Navigate2(r ef loc , ref null_obj, ref null_obj, ref null_obj_str, ref null_obj_str);
    }
    }
    }
  • brightlight
    New Member
    • Mar 2008
    • 5

    #2
    The problem solved with a fresh mind. I use a textbox and update it after button clicked. After page fully loaded it automatically gets thhe updated textbox..

    take care...

    Comment

    Working...