browser.coffee | |
|---|---|
| | |
| Browser options you can set when creating new browser, or on browser instance. | undefined |
| Global options you can set on Browser and will be inherited by each new browser. | undefined |
| Use the browser to open up new windows and load documents. The browser maintains state for cookies and localStorage. | undefined |
| Make sure we don't blow up Node when we get a JS error, but dump error to console. Also, catch any errors reported while processing resources/JavaScript. | undefined |
| Default (not global) options | undefined |
| Send this referer. | undefined |
| You can set the browser window.name property | undefined |
| Sets the browser options. | undefined |
| Returns all errors reported while loading this window. | undefined |
Global options | undefined |
| True to have Zombie report what it's doing. | undefined |
| Which parser to use (HTML5 by default). For example: Browser.htmlParser = require("html5").HTML5 // HTML5, forgiving Browser.htmlParser = require("htmlparser") // Faster, stricter | undefined |
| True to load external stylesheets. | undefined |
| Maximum time to wait (visit, wait, etc). | undefined |
| Proxy URL. Example Browser.proxy = "http://myproxy:8080" browser.visit("site", function(error, browser) { }) | undefined |
| Run scripts included in or loaded from the page. Defaults to true. | undefined |
| If true, supress | undefined |
| User agent string sent to server. | undefined |
| You can use visit with a path, and it will make a request relative to this host/URL. | undefined |
| Tells | undefined |
| Additional headers to be sent with each HTTP request | undefined |
| Changes the browser options, and calls the function with a callback (reset). When you're done processing, call the reset function to bring options back to their previous values. See | undefined |
| Return a new browser with a snapshot of this browser's state. Any changes to the forked browser's state do not affect this browser. | undefined |
Windows | undefined |
| Returns the currently open window | undefined |
| Open new browser window. Options are undocumented, use at your own peril. | undefined |
browser.error => ErrorReturns the last error reported while loading this window. | undefined |
Events | undefined |
| Waits for the browser to complete loading resources and processing JavaScript events. You can pass a callback as the last argument. Without a callback, this method returns a promise. With Without duration, Zombie makes best judgement by waiting up to 5 seconds for the page to load resources (scripts, XHR requests, iframes), process DOM events, and fire timeouts events. | undefined |
| Fire a DOM event. You can use this to simulate a DOM event, e.g. clicking a link. These events will bubble up and
can be cancelled. Like name - Even name (e.g | undefined |
| Dispatch asynchronously. Returns true if preventDefault was set. | undefined |
Accessors | undefined |
browser.queryAll(selector, context?) => ArrayEvaluates the CSS selector against the document (or context node) and return array of nodes.
(Unlike | undefined |
browser.query(selector, context?) => ElementEvaluates the CSS selector against the document (or context node) and return an element. | undefined |
browser.querySelector(selector) => ElementSelect a single element (first match) and return it. selector - CSS selector Returns an Element or null | undefined |
browser.querySelectorAll(selector) => NodeListSelect multiple elements and return a static node list. selector - CSS selector Returns a NodeList or null | undefined |
browser.text(selector, context?) => StringReturns the text contents of the selected elements. selector - CSS selector (if missing, entire document) context - Context element (if missing, uses document) Returns a string | undefined |
browser.html(selector?, context?) => StringReturns the HTML contents of the selected elements. selector - CSS selector (if missing, entire document) context - Context element (if missing, uses document) Returns a string | undefined |
| Deprecated please use | undefined |
browser.xpath(expression, context?) => XPathResultEvaluates the XPath expression against the document (or context node) and return the XPath result. Shortcut for
| undefined |
browser.document => DocumentReturns the main window's document. Only valid after opening a document (see | undefined |
browser.body => ElementReturns the body Element of the current document. | undefined |
browser.statusCode => NumberReturns the status code of the request for loading the window. | undefined |
browser.success => BooleanTrue if the status code is 2xx. | undefined |
browser.redirected => BooleanReturns true if the request for loading the window followed a redirect. | undefined |
source => StringReturns the unmodified source of the document loaded by the browser | undefined |
closeClose all windows, dispose of all resources. You want to call this if you're running out of memory. | undefined |
Navigation | undefined |
browser.visit(url, callback?)browser.visit(url, options, callback)Loads document from the specified URL, processes events and calls the callback. If the second argument are options, uses these options for the duration of the request and resets the options afterwards. The callback is called with null, the browser, status code and array of resource/JavaScript errors. | undefined |
browser.load(html, callback)Loads the HTML, processes events and calls the callback. Without a callback, returns a promise. | undefined |
| Find (first of any) errors caught during document.write | undefined |
| Call callback or resolve promise | undefined |
| Otherwise wait for all events to process, wait handles errors | undefined |
browser.location => LocationReturn the location of the current document (same as | undefined |
browser.location = urlChanges document location, loads new document if necessary (same as setting | undefined |
browser.link(selector) : ElementFinds and returns a link by its text content or selector. | undefined |
| If the link has already been queried, return itself | undefined |
browser.clickLink(selector, callback)Clicks on a link. Clicking on a link can trigger other events, load new page, etc: use a callback to be notified of completion. Finds link by text content or selector. selector - CSS selector or link text callback - Called with two arguments: error and browser | undefined |
| Return the history object. | undefined |
| Navigate back in history. | undefined |
| Reloads current page. | undefined |
| Returns a new Credentials object for the specified host. These authentication credentials will only apply when making requests to that particular host (hostname:port). You can also set default credentials by using the host '*'. If you need to get the credentials without setting them, call with true as the second argument. | undefined |
| Legacy support, remove in the future. | undefined |
browser.saveHistory() => StringSave history to a text string. You can use this to load the data later on using | undefined |
browser.loadHistory(String)Load history from a text string (e.g. previously created using | undefined |
Forms | undefined |
browser.field(selector) : ElementFind and return an input field ( | undefined |
| If the field has already been queried, return itself | undefined |
| Try more specific selector first. | undefined |
| Use field name (case sensitive). | undefined |
| Try finding field from label. | undefined |
| Label can either reference field or enclose it | undefined |
browser.fill(selector, value, callback) => thisFill in a field: input field or text area. selector - CSS selector, field name or text of the field label value - Field value Without callback, returns this. | undefined |
browser.check(selector, callback) => thisChecks a checkbox. selector - CSS selector, field name or text of the field label Without callback, returns this. | undefined |
browser.uncheck(selector, callback) => thisUnchecks a checkbox. selector - CSS selector, field name or text of the field label Without callback, returns this. | undefined |
browser.choose(selector, callback) => thisSelects a radio box option. selector - CSS selector, field value or text of the field label Returns this. | undefined |
browser.select(selector, value, callback) => thisSelects an option. selector - CSS selector, field name or text of the field label value - Value (or label) or option to select Without callback, returns this. | undefined |
browser.selectOption(option, callback) => thisSelects an option. option - option to select Without callback, returns this. | undefined |
browser.unselect(selector, value, callback) => thisUnselects an option. selector - CSS selector, field name or text of the field label value - Value (or label) or option to unselect Without callback, returns this. | undefined |
browser.unselectOption(option, callback) => thisUnselects an option. option - option to unselect Without callback, returns this. | undefined |
browser.attach(selector, filename, callback) => thisAttaches a file to the specified input field. The second argument is the file name. Without callback, returns this. | undefined |
browser.button(selector) : ElementFinds a button using CSS selector, button name or button text ( selector - CSS selector, button name or text of BUTTON element | undefined |
| If the button has already been queried, return itself | undefined |
browser.pressButton(selector, callback)Press a button (button element or input of type selector - CSS selector, button name or text of BUTTON element callback - Called with two arguments: null and browser | undefined |
browser.focused => elementReturns the element in focus. | undefined |
Cookies and storage | undefined |
| Returns all the cookies for this domain/path. Domain defaults to hostname of currently open page. Path defaults to "/". | undefined |
| Save cookies to a text string. You can use this to load them back later on using | undefined |
| Load cookies from a text string (e.g. previously created using | undefined |
| Returns local Storage based on the document origin (hostname/port). This is the same storage area you can access from any document of that origin. | undefined |
| Returns session Storage based on the document origin (hostname/port). This is the same storage area you can access from any document of that origin. | undefined |
| Save local/session storage to a text string. You can use this to load the data later on using
| undefined |
| Load local/session stroage from a text string (e.g. previously created using | undefined |
Scripts | undefined |
| Evaluates a JavaScript expression in the context of the current window and returns the result. When evaluating external script, also include filename. You can also use this to evaluate a function in the context of the window: for timers and asynchronous callbacks (e.g. XHR). | undefined |
Interaction | undefined |
browser.onalert(fn)Called by | undefined |
browser.onconfirm(question, response)browser.onconfirm(fn)The first form specifies a canned response to return when The response to the question can be true or false, so all canned responses are converted to either value. If no response available, returns false. | undefined |
browser.onprompt(message, response)browser.onprompt(fn)The first form specifies a canned response to return when The response to a prompt can be any value (converted to a string), false to indicate the user cancelled the prompt (returning null), or nothing to have the prompt return the default value or an empty string. | undefined |
browser.prompted(message) => booleanReturns true if user was prompted with that message ( | undefined |
Debugging | undefined |
browser.viewInBrowser(name?)Views the current document in a real Web browser. Uses the default system browser on OS X, BSD and Linux. Probably errors on Windows. | undefined |
browser.lastRequest => HTTPRequestReturns the last request sent by this browser. The object will have the properties url, method, headers, and body. | undefined |
browser.lastResponse => HTTPResponseReturns the last response received by this browser. The object will have the properties url, status, headers and body. Long bodies may be truncated. | undefined |
browser.lastError => ObjectReturns the last error received by this browser in lieu of response. | undefined |
| Zombie can spit out messages to help you figure out what's going on as your code executes. To spit a message to the console when running in debug mode, call this method with one or more values (same as
For example: browser.log("Opening page:", url); browser.log(function() { return "Opening page: " + url }); | undefined |
| Dump information to the consolt: Zombie version, current URL, history, cookies, event loop, etc. Useful for debugging and submitting error reports. | undefined |
| Represents credentials for a given host. | undefined |
| Apply security credentials to the outgoing request headers. | undefined |
| Use HTTP Basic authentication. Requires two arguments, username and password. | undefined |
| Use OAuth 2.0 Bearer (recent drafts). Requires one argument, the access token. | undefined |
| Use OAuth 2.0 (early drafts). Requires one argument, the access token. | undefined |
| Reset these credentials. | undefined |