Exemple #1
0
        public static object invokeEval(this WatiN_IE ie, string evalScript)
        {
            var evalParam = "(function() { " + evalScript + "})();";

            //"[WatiN_IE] invokeEval evalParam: {0}".debug(evalParam);
            return(ie.invokeScript("eval", evalParam));
        }
Exemple #2
0
        /// <summary>
        /// Searches all elements for the an element that matches the provided value.
        ///
        /// The value returned is the first match, and the search order is:
        ///     - Html Tag name
        ///     - id attribute
        ///     - innerHtml
        /// </summary>
        /// <param name="watinIe"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Element element(this WatiN_IE watinIe, string value)
        {
            if (watinIe.isNull() || value.notValid())
            {
                return(null);
            }
            var element_by_Tag = watinIe.elements().with_TagName(value);

            if (element_by_Tag.notNull())
            {
                return(element_by_Tag);
            }

            var element_by_Id = watinIe.elements().with_Id(value);

            if (element_by_Id.notNull())
            {
                return(element_by_Id);
            }

            var element_by_InnerText = watinIe.elements().with_InnerText(value);

            if (element_by_InnerText.notNull())
            {
                return(element_by_InnerText);
            }
            return(null);
        }
 public static List <T> elements <T>(this WatiN_IE watinIe)
     where T : Element
 {
     return((from element in watinIe.elements()
             where element is T
             select(T) element).toList());
 }
Exemple #4
0
 public static WatiN_IE open_usingPOST(this WatiN_IE watinIe, string postUrl, string contentType, string postData)
 {
     try
     {
         "[WatIN] open using POST: {0} ({1} bytes)".info(postUrl, postData.size());
         var browser = (watinIe.IE.InternetExplorer as IWebBrowser2);
         if (browser.notNull())
         {
             object postDataByte      = Encoding.UTF8.GetBytes(postData);
             object additionalHeaders = "Content-Type: " + contentType.line();
             object nullValue         = null;
             browser.Navigate(postUrl, ref nullValue, ref nullValue, ref postDataByte, ref additionalHeaders);
             watinIe.IE.WaitForComplete();
         }
         else
         {
             "[WatiN_IE open_usingPOST] could not get a reference to the browser object".error();
         }
     }
     catch (Exception ex)
     {
         ex.log("in WatiN_IE open_usingPOST");
     }
     return(watinIe);
 }
Exemple #5
0
        public static WatiN_IE openWithExtraHeader(this WatiN_IE watinIe, string url, string extraHeader)
        {
            try
            {
                "[WatIN] open with extra Header: {0} ({1} bytes)".info(url, extraHeader.size());
                object headerObject = extraHeader.line();
                object flags        = null;
                var    iWebBrowser  = watinIe.iWebBrowser();
                if (iWebBrowser.notNull())
                {
                    iWebBrowser.Navigate(url,
                                         ref flags,
                                         ref flags,
                                         ref flags,
                                         ref headerObject);
                    watinIe.IE.WaitForComplete();
                }
            }
            catch (Exception ex)
            {
                ex.log("in WatiN_IE openWithExtraHeader(...)");
            }

            return(watinIe);
        }
Exemple #6
0
        public static WatiN_IE deleteJsVariable(this WatiN_IE watinIe, string jsVariable)
        {
            var evalString = "try { delete " + jsVariable + " } catch(exception) { }";

            watinIe.eval(evalString);
            return(watinIe);
        }
Exemple #7
0
        // region close

        public static WatiN_IE close(this WatiN_IE watinIe)
        {
            "closing WatIN InternetExplorer Process".info();
            watinIe.close();
            //watinIe.Close();
            return(watinIe);
        }
Exemple #8
0
        public static string html(this WatiN_IE ie)
        {
            try
            {
                return(ie.IE.Html);
            }
            catch (Exception ex)
            {
                ex.log("in WatiN_IE html()");
                return(null);
            }
            //return ie.documentElement().html();

            /*
             *          try
             *  {
             *          if (ie.IE.InternetExplorer.notNull() && ie.IE.InternetExplorer is IWebBrowser2)
             *          {
             *                  var webBrowser = (IWebBrowser2)ie.IE.InternetExplorer;
             *                  if (webBrowser.Document.notNull() && webBrowser.Document is HTMLDocumentClass)
             *                  {
             *                          var htmlDocument = (HTMLDocumentClass)webBrowser.Document;
             *                          if (htmlDocument.documentElement.notNull())
             *                                  return htmlDocument.documentElement.outerHTML;
             *                  }
             *          }
             *  }
             *  catch(Exception ex)
             *  {
             *          ex.log("in WatiN_IE html()");
             *  }
             *  return "";*/
        }
Exemple #9
0
        public static WatiN_IE.ToCSharp injectJavascriptFunctions(this WatiN_IE ie, bool resetHooks)
        {
            if (ie.WebBrowser.isNull())
            {
                "in InjectJavascriptFunctions, ie.WebBrowser was null".error();
            }
            else
            {
                if (ie.WebBrowser.ObjectForScripting.isNull() || resetHooks)
                {
                    ie.WebBrowser.ObjectForScripting = new WatiN_IE.ToCSharp();

                    "Injecting Javascript Hooks * Functions for page: {0}".debug(ie.url());
                    ie.eval("var o2Log = function(message) { window.external.write(message) };");
                    ie.invokeScript("o2Log", "Test from Javascript (via toCSharp(message) )");
                    ie.eval("$o2 = window.external");
                    "Injection complete (use o2Log(...) or $o2.write(...)  to talk back to O2".info();
                    return(ie.WebBrowser.ObjectForScripting as WatiN_IE.ToCSharp);
                }
                else
                {
                    if ((ie.WebBrowser.ObjectForScripting is WatiN_IE.ToCSharp))
                    {
                        return(ie.WebBrowser.ObjectForScripting as WatiN_IE.ToCSharp);
                    }
                    else
                    {
                        "in WatiN_IE injectJavascriptFunctions, unexpected type in ie.WebBrowser.ObjectForScripting: {0}".error(ie.WebBrowser.ObjectForScripting.typeName());
                    }
                }
            }
            return(null);
        }
Exemple #10
0
 public static DispHTMLHtmlElement htmlDocumentElement(this WatiN_IE ie)
 {
     try
     {
         var htmlDocument = ie.htmlDocument();
         if (htmlDocument.notNull())
         {
             var htmlDocumentElement = htmlDocument.documentElement;
             var comTypeName         = htmlDocumentElement.comObject_TypeName();
             if (htmlDocumentElement.notNull())
             {
                 /* in an previous version it was HTMLHtmlElementClass
                  *
                  * if (htmlDocumentElement is HTMLHtmlElementClass)
                  * return (HTMLHtmlElementClass)htmlDocumentElement;
                  */
                 if (htmlDocumentElement is DispHTMLHtmlElement)
                 {
                     return((DispHTMLHtmlElement)htmlDocumentElement);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ex.log("in WatiN_IE htmlDocumentElement()");
     }
     return(null);
 }
Exemple #11
0
        public static string formatJsCode(this WatiN_IE ie, string codeToFormat)
        {
            if (ie.url().not_Equal("about:blank"))
            {
                "opening ABOUT:Blank".info();
                ie.open("about:blank");
            }
            else
            {
                "already in ABOUT:Blank".info();
            }

            if (ie.js_FunctionExists("js_beautify").isFalse())
            {
                var jsBeautify = @"beautify.js".local();
                ie.eval(jsBeautify.fileContents());
                if (ie.js_FunctionExists("js_beautify"))
                {
                    "Injected beautify.js into about:blank".info();
                }
                else
                {
                    "Failed to Inject js_beautify code".error();
                }
            }
            "formating Javascript with size: {0}".info(codeToFormat.size());
            ie.setJsObject(codeToFormat);
            ie.eval("window.external.setJsObject(js_beautify(_jsObject))");
            var result = ie.getJsObject().str().fix_CRLF();

//			"formated Javascript has size: {0}".info(result.size());
            return(result);
        }
        public static WatiN_IE ie(this string url, int top, int left, int width, int height)
        {
            var ie = new WatiN_IE();

            ie.createIEObject(url, top, left, width, height);
            return(ie);
        }
Exemple #13
0
 public static List <WatiN.Core.RadioButton> radioButtons(this WatiN_IE watinIe, string name)
 {
     return((from radioButton in watinIe.IE.RadioButtons
             where (radioButton.name() == name)
             select radioButton
             ).toList());
 }
Exemple #14
0
 public static WatiN_IE waitNSeconds(this WatiN_IE watinIe, int seconds)
 {
     if (seconds > 0)
     {
         watinIe.sleep(seconds * 1000);
     }
     return(watinIe);
 }
Exemple #15
0
 public static WatiN_IE if_NoPageLoaded(this WatiN_IE watinIe, Action callback)
 {
     if (watinIe.noPageLoaded())
     {
         callback();
     }
     return(watinIe);
 }
        public static WatiN_IE inject_FirebugLite(this WatiN_IE ie)
        {
            var firebugLiteScript = "(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');";

            ie.eval(firebugLiteScript);
            "[Injected FirebugLite]".info();
            return(ie);
        }
Exemple #17
0
 public static WatiN_IE      refresh(this WatiN_IE ie)
 {
     if (ie.url().valid())
     {
         ie.open(ie.url());
     }
     return(ie);
 }
Exemple #18
0
 /// <summary>
 /// Returns the parent WindForm Form object (note that this is NOT a WatiN.Core.Form object)
 ///
 /// This is the same as calling <code>watinIe.HostControl.parentForm()</code>
 /// </summary>
 /// <param name="watinIe"></param>
 /// <returns>System.Windows.Forms.Form</returns>
 public static System.Windows.Forms.Form parentForm(this WatiN_IE watinIe)
 {
     if (watinIe.notNull() && watinIe.HostControl.notNull())
     {
         return(watinIe.HostControl.parentForm());
     }
     return(null);
 }
Exemple #19
0
 public static WatiN_IE wait(this WatiN_IE watinIe, int miliseconds)
 {
     if (WatiN_IE.WaitingEnabled && miliseconds > 0)
     {
         watinIe.sleep(miliseconds);
     }
     return(watinIe);
 }
 public static WatiN.Core.Image image(this WatiN_IE watinIe, string name)
 {
     foreach(var image in watinIe.images())
         if (image.id() == name)//|| link.text() == name)
             return image;
     "in WatiN_IE could not find Image with name:{0}".error(name ?? "[null value]");
     return null;
 }
 public static DialogWatcher getDialogWatcher(this WatiN_IE watinIe)
 {
     if (watinIe.isNull() || watinIe.IE.isNull())
     {
         return(null);
     }
     watinIe.setDialogWatcher();
     return(watinIe.IE.DialogWatcher);
 }
Exemple #22
0
 public static List <Link> links(this WatiN_IE watinIe)
 {
     if (watinIe.notNull() && watinIe.IE.notNull())
     {
         return((from link in watinIe.IE.Links
                 select link).toList());
     }
     return(new List <Link>());
 }
Exemple #23
0
        public static string askUserQuestion(this WatiN_IE watinIe, string question, string title, string defaultValue)
        {
            var assembly    = "Microsoft.VisualBasic".assembly();
            var intercation = assembly.type("Interaction");

            var parameters = new object[] { question, title, defaultValue, -1, -1 };

            return(intercation.invokeStatic("InputBox", parameters).str());
        }
        public static T javascript_VariableValue <T>(this WatiN_IE ie, string variableName)
        {
            var result = ie.javascript_VariableValue(variableName);

            if (result is T)
            {
                return((T)result);
            }
            return(default(T));
        }
Exemple #25
0
        public static Credential askUserForUsernameAndPassword(this WatiN_IE watinIe, string loginType)
        {
            var credential = ascx_AskUserForLoginDetails.ask();

            if (loginType.valid())
            {
                credential.CredentialType = loginType;
            }
            return(credential);
        }
Exemple #26
0
        public static string url(this WatiN_IE watinIe)
        {
            var uri = watinIe.uri();

            if (uri.notNull())
            {
                return(uri.str());
            }
            return(null);
        }
Exemple #27
0
        public static T getJsObject <T>(this WatiN_IE ie, string jsCommand)
        {
            var jsObject = ie.getJsObject(jsCommand);

            if (jsObject is T)
            {
                return((T)jsObject);
            }
            return(default(T));
        }
Exemple #28
0
        public static object getJsObject(this WatiN_IE ie)
        {
            var toCSharpProxy = ie.injectJavascriptFunctions();

            if (toCSharpProxy.notNull())
            {
                return(toCSharpProxy.getJsObject());
            }
            return(null);
        }
Exemple #29
0
        public static WatiN_IE eval(this WatiN_IE ie, string script, bool waitForExecutionComplete)
        {
            var executionThread = O2Thread.staThread(() => ie.IE.RunScript(script));

            if (waitForExecutionComplete)
            {
                executionThread.Join();
            }
            return(ie);
        }
        public static WatiN_IE  fullScreen(this WatiN_IE ie, bool value)
        {
            var internetExplorer = ie.internetExplorer();

            if (internetExplorer.notNull())
            {
                internetExplorer.FullScreen = value;
            }
            return(ie);
        }