// Generating method code for compile public virtual net.sourceforge.htmlunit.corejs.javascript.Script Compile(NHtmlUnit.Html.HtmlPage htmlPage, string sourceCode, string sourceName, int startLine) { return(WObj.compile((com.gargoylesoftware.htmlunit.html.HtmlPage)htmlPage.WrappedObject, sourceCode, sourceName, startLine)); }
// Generating method code for callFunction public virtual object CallFunction(NHtmlUnit.Html.HtmlPage htmlPage, net.sourceforge.htmlunit.corejs.javascript.Function function, net.sourceforge.htmlunit.corejs.javascript.Scriptable scope, net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObject, System.Object[] args) { return(WObj.callFunction((com.gargoylesoftware.htmlunit.html.HtmlPage)htmlPage.WrappedObject, function, scope, thisObject, args)); }
// Generating method code for callFunction public virtual object CallFunction(NHtmlUnit.Html.HtmlPage htmlPage, net.sourceforge.htmlunit.corejs.javascript.Function javaScriptFunction, net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObject, System.Object[] args, NHtmlUnit.Html.DomNode htmlElement) { return(WObj.callFunction((com.gargoylesoftware.htmlunit.html.HtmlPage)htmlPage.WrappedObject, javaScriptFunction, thisObject, args, (com.gargoylesoftware.htmlunit.html.DomNode)htmlElement.WrappedObject)); }
// Generating method code for execute public virtual object Execute(NHtmlUnit.Html.HtmlPage htmlPage, net.sourceforge.htmlunit.corejs.javascript.Script script) { return(WObj.execute((com.gargoylesoftware.htmlunit.html.HtmlPage)htmlPage.WrappedObject, script)); }
// Generating method code for execute public virtual object Execute(NHtmlUnit.Html.HtmlPage htmlPage, string sourceCode, string sourceName, int startLine) { return(WObj.execute((com.gargoylesoftware.htmlunit.html.HtmlPage)htmlPage.WrappedObject, sourceCode, sourceName, startLine)); }
public ScriptException(NHtmlUnit.Html.HtmlPage page, System.Exception throwable) : this(new com.gargoylesoftware.htmlunit.ScriptException((com.gargoylesoftware.htmlunit.html.HtmlPage)page.WrappedObject, throwable)) { }
// Generating method code for processSynchron public virtual bool ProcessSynchron(NHtmlUnit.Html.HtmlPage page, NHtmlUnit.WebRequest request, bool async) { return(WObj.processSynchron((com.gargoylesoftware.htmlunit.html.HtmlPage)page.WrappedObject, (com.gargoylesoftware.htmlunit.WebRequest)request.WrappedObject, async)); }
static void Main(string[] args) { /* Set the client to mimic Firefox. By default I believe it mimics IE, and that implementation has some issues. For example, the call below * to generateLink.Click() fails when the default WebClient constructor is called (IE), but succeeds when Firefox is mimiced. This seems to be a * jQuery problem - see https://github.com/playframework/playframework/issues/5050 et. al. * */ WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38); // This actually takes us to the /index page in test-login.py, but since we're not logged in yet, it will bump us to /auth/login, // then back to /index once the login is successful. NHtmlUnit.Html.HtmlPage currentPage = webClient.GetHtmlPage("http://127.0.0.1:8080"); /* * At this point we assume that we're on /index, but it's always a good idea to check. Two ways to do this are: * * 1. currentPage.BaseURL.ToString() (assuming you're confident of the page's content once you know the URL) * 2. currentPage.AsText(), and then parse the string to determine the page's content, looking for specific text - especially * useful if the page is dynamically-generated, and you don't know if what you're looking for is present (or present yet). */ NHtmlUnit.Html.HtmlTextInput username = (NHtmlUnit.Html.HtmlTextInput)currentPage.GetElementByName("username"); username.Text = "joe"; NHtmlUnit.Html.HtmlPasswordInput password = (NHtmlUnit.Html.HtmlPasswordInput)currentPage.GetElementByName("password"); password.Text = "secret"; /* * The login button has no name or ID (see auth.py, get_loginform) - so we need to iterate through each HTML element to find it. We could give it * a name or ID, but the code below highlights how to handle a situation where we have no control over the web page. */ NHtmlUnit.Html.HtmlSubmitInput loginButton = null; bool foundLoginButton = false; foreach (NHtmlUnit.Html.HtmlElement el in currentPage.TabbableElements) { if (!foundLoginButton) { try { //try casting each element to a submit button - the right one will succeed, the wrong ones will throw exceptions loginButton = (NHtmlUnit.Html.HtmlSubmitInput)el; foundLoginButton = true; } catch (Exception /*ee*/) { //keep looking for it } } } currentPage = (NHtmlUnit.Html.HtmlPage)loginButton.Click(); //The Click() method returns when the next page (which is /index) is loaded. We'll go to the "Generate Random String" link and "click" it. // It would be simpler to just call GetHtmlPage("/generate"), but this highlights a useful feature - moving to a page where we know the link // text, but not the URL. If you know the URL but not the text, use GetAnchorByHref() NHtmlUnit.Html.HtmlAnchor generateLink = currentPage.GetAnchorByText("Generate Random String"); currentPage = (NHtmlUnit.Html.HtmlPage)generateLink.Click(); //The Click() method returns when the next page (which is /generate) is loaded. NHtmlUnit.Html.HtmlButton generateButton = (NHtmlUnit.Html.HtmlButton)currentPage.GetElementById("generate-string"); generateButton.Click(); NHtmlUnit.Html.HtmlTextInput randomString = (NHtmlUnit.Html.HtmlTextInput)currentPage.GetElementById("random-string"); string theRandomString = randomString.Text; /* * Ah-ha!!! At this point, the value of theRandomString will be empty, even though one might think that it should contain the random string. * Even if you (in the debugger) stop on a breakpoint immediately after generateButton.Click() for hours, the string will be empty. * We need to tell the web client to wait (e.g. for 500ms) for the Javascript to complete - this function *also* updates the state of the HtmlPage * object (and child objects like text inputs), so we can read the random string. */ webClient.WaitForBackgroundJavaScript(500); theRandomString = randomString.Text; Console.WriteLine(theRandomString); webClient.GetHtmlPage("/auth/logout"); currentPage.CleanUp(); webClient.Close(); }
// Generating method code for definePropertiesInStandardsMode public virtual void DefinePropertiesInStandardsMode(NHtmlUnit.Html.HtmlPage page) { WObj.definePropertiesInStandardsMode((com.gargoylesoftware.htmlunit.html.HtmlPage)page.WrappedObject); }