Ejemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            browser = BrowserFactory.Create();
            BrowserView browserView = new WinFormsBrowserView(browser);

            this.Controls.Add((Control)browserView.GetComponent());

            browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
            {
                if (e.IsMainFrame)
                {
                    DOMDocument      document = e.Browser.GetDocument();
                    DOMSelectElement select   = (DOMSelectElement)document.GetElementById("select-tag");
                    select.Value = "opel";
                }
            };
            browserView.Browser.LoadHTML("<html><body><select id='select-tag'>\n" +
                                         "  <option value=\"volvo\">Volvo</option>\n" +
                                         "  <option value=\"saab\">Saab</option>\n" +
                                         "  <option value=\"opel\">Opel</option>\n" +
                                         "  <option value=\"audi\">Audi</option>\n" +
                                         "</select></body></html>");;
        }
Ejemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();

            browser = BrowserFactory.Create();
            BrowserView browserView = new WinFormsBrowserView(browser);

            browserView.Browser.DialogHandler = new WinFormsDefaultDialogHandler((Control)browserView.GetComponent());

            this.Controls.Add((Control)browserView.GetComponent());

            DOMEventHandler domEvent = delegate(object sender, DOMEventArgs e)
            {
                DOMEventType eventType = e.Type;
                Console.Out.WriteLine("handleEvent = " + eventType);
            };


            browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
            {
                if (e.IsMainFrame)
                {
                    DOMDocument document        = e.Browser.GetDocument();
                    DOMElement  documentElement = document.DocumentElement;
                    documentElement.AddEventListener(DOMEventType.OnClick | DOMEventType.OnMouseDown | DOMEventType.OnMouseUp | DOMEventType.OnKeyDown, domEvent, false);
                }
            };

            browserView.Browser.LoadURL("http://www.teamdev.com");
        }
Ejemplo n.º 3
0
        public Form1()
        {
            InitializeComponent();

            browser = BrowserFactory.Create();
            BrowserView browserView = new WinFormsBrowserView(browser);

            browserView.Browser.DialogHandler = new WinFormsDefaultDialogHandler((Control)browserView.GetComponent());

            this.Controls.Add((Control)browserView.GetComponent());

            browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
            {
                if (e.IsMainFrame)
                {
                    Browser     myBrowser = e.Browser;
                    DOMDocument document  = myBrowser.GetDocument();
                    DOMElement  link      = document.GetElementById("button");
                    if (link != null)
                    {
                        link.Click();
                    }
                }
            };
            browserView.Browser.LoadHTML("<html><body><button id='button' " +
                                         "onclick=\"alert('Button has been clicked!');\">Click Me!</button>" +
                                         "</body></html>");
        }
Ejemplo n.º 4
0
        public Form1()
        {
            InitializeComponent();

            browser = BrowserFactory.Create();
            BrowserView browserView = new WinFormsBrowserView(browser);

            browser.DialogHandler = new WinFormsDefaultDialogHandler((Control)browserView);

            this.Controls.Add((Control)browserView.GetComponent());

            browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
            {
                if (e.IsMainFrame)
                {
                    DOMDocument document = e.Browser.GetDocument();

                    DOMElement      link3Element = document.GetElementById("link3");
                    DOMEventHandler link3Event   = delegate(object domEventSender, DOMEventArgs domEventArgs)
                    {
                        if (domEventArgs.Type == DOMEventType.OnFocus)
                        {
                            Console.Out.WriteLine("link3 gets focus");
                        }
                        if (domEventArgs.Type == DOMEventType.OnBlur)
                        {
                            Console.Out.WriteLine("Remove focus from link3");
                        }
                    };
                    link3Element.AddEventListener(DOMEventType.OnFocus | DOMEventType.OnBlur, link3Event, false);


                    DOMElement elementFocused = null;
                    foreach (DOMElement element in document.GetElementsByTagName("a"))
                    {
                        Thread.Sleep(2000);
                        element.Focus();
                        elementFocused = element;
                    }

                    if (elementFocused != null)
                    {
                        Thread.Sleep(2000);
                        elementFocused.Blur();
                    }
                }
            };
            browserView.Browser.LoadHTML(@"<html>
                                                <body>
                                                    <a id='link1' href='#'>The link 1</a>
                                                    <a id='link2' href='#'>The link 2</a>
                                                    <a id='link3' href='#'>The link 3</a>
                                                    <script type='text/javascript'>
                                                        var link2 = document.getElementById('link2');
                                                        link2.addEventListener('focus', function () { console.log('link2 gets focus'); });
                                                        link2.addEventListener('blur', function () { console.log('Remove focus from link2'); });
                                                    </script>
                                                </body>
                                            </html>");
        }
Ejemplo n.º 5
0
        public Form1()
        {
            InitializeComponent();

            browser = BrowserFactory.Create();
            BrowserView browserView = new WinFormsBrowserView(browser);

            browser.ContextMenuHandler = new MyContextMenuHandler((Control)browserView);
            this.Controls.Add((Control)browserView.GetComponent());

            browser.LoadURL("http://www.google.com");
        }
Ejemplo n.º 6
0
        public Form1()
        {
            InitializeComponent();

            browser = BrowserFactory.Create();
            browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
            {
                if (e.IsMainFrame)
                {
                    // Press TAB key to set focus to text field.
                    KeyParams paramers = new KeyParams(VirtualKeyCode.TAB, ' ');
                    browser.KeyDown(paramers);
                    browser.KeyUp(paramers);

                    // Type 'Hello' text in the focused text field.
                    paramers = new KeyParams(VirtualKeyCode.VK_H, 'H');
                    browser.KeyDown(paramers);
                    browser.KeyUp(paramers);

                    paramers = new KeyParams(VirtualKeyCode.VK_E, 'e');
                    browser.KeyDown(paramers);
                    browser.KeyUp(paramers);

                    paramers = new KeyParams(VirtualKeyCode.VK_L, 'l');
                    browser.KeyDown(paramers);
                    browser.KeyUp(paramers);

                    paramers = new KeyParams(VirtualKeyCode.VK_L, 'l');
                    browser.KeyDown(paramers);
                    browser.KeyUp(paramers);

                    paramers = new KeyParams(VirtualKeyCode.VK_O, 'o');
                    browser.KeyDown(paramers);
                    browser.KeyUp(paramers);
                }
            };

            BrowserView browserView = new WinFormsBrowserView(browser);

            browserView.Browser.LoadHTML(@"<html><body><input type='text'></input></body></html>");

            this.Controls.Add((Control)browserView.GetComponent());
        }
Ejemplo n.º 7
0
        public Form1()
        {
            InitializeComponent();
            browser = BrowserFactory.Create();

            browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
            {
                if (e.IsMainFrame)
                {
                    JSValue value = browser.ExecuteJavaScriptAndReturnValue("window");
                    value.AsObject().SetProperty("Account", new Account());
                }
            };

            browser.LoadHTML(@"<!DOCTYPE html>
                                    <html>
                                    <head>
                                        <script type='text/javascript'>
                                              function sendFormData() {
                                                var firstNameValue = myForm.elements['firstName'].value;
                                                var lastNameValue = myForm.elements['lastName'].value;
                                                // Invoke the 'save' method of the 'Account' Java object.
                                                Account.Save(firstNameValue, lastNameValue);
                                              }
                                            </script>
                                    </head>
                                    <body>
                                    <form name='myForm'>
                                        First name: <input type='text' name='firstName'/>
                                        <br/>
                                        Last name: <input type='text' name='lastName'/>
                                        <br/>
                                        <input type='button' value='Save' onclick='sendFormData();'/>
                                    </form>
                                    </body>
                                    </html>");


            BrowserView browserView = new WinFormsBrowserView(browser);

            this.Controls.Add((Control)browserView.GetComponent());
        }
Ejemplo n.º 8
0
        public Form1()
        {
            InitializeComponent();

            browser = BrowserFactory.Create();
            BrowserView browserView = new WinFormsBrowserView(browser);

            this.Controls.Add((Control)browserView.GetComponent());

            browserView.Browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
            {
                if (e.IsMainFrame)
                {
                    DOMDocument document = e.Browser.GetDocument();
                    DOMElement  button   = document.GetElementById("button-id");
                    button.Children[0].NodeValue = "New Button Name";
                }
            };
            browserView.Browser.LoadHTML("<html><body><button id='button-id'>Button</button></body></html>");
        }