SimpleBrowser
public class SimpleBrowser
Constructor Summary | |
---|---|
Starts with a fresh browser with no cookie or any other state information. |
Method Summary | |
---|---|
void | addHeader(string header) Adds a header to every fetch. |
void | ageCookies(integer interval) Ages the cookies by the specified time. |
boolean | authenticate(string username, string password) Retries a request after setting the authentication for the current realm. |
boolean | back() Equivalent to hitting the back button on the browser. |
void | Clears the frame focus. |
string/boolean | clickImage(string label, integer x, integer y, hash additional) Clicks the submit image by some kind of label. |
string/boolean | clickImageById(integer/string id, integer x, integer y, hash additional) Clicks the submit image by ID attribute. |
string/boolean | clickImageByName(string name, integer x, integer y, hash additional) Clicks the submit image by the name. |
string/boolean | clickLink(string label, integer index) Follows a link by label. |
string/boolean | clickLinkById(string id) Follows a link by id attribute. |
string/boolean | clickSubmit(string label, hash additional) Clicks the submit button by label. |
string/boolean | clickSubmitById(string id, hash additional) Clicks the submit button by ID attribute of the button itself. |
string/boolean | clickSubmitByName(string name, hash additional) Clicks the submit button by name attribute. |
boolean | forward() Equivalent to hitting the forward button on the browser. |
string | get(string/SimpleUrl url, hash/SimpleFormEncoding parameters) Fetches the page content with a simple GET request. |
array | Accessor for a list of all fixed links in current page. |
string | Accessor for last Authentication type. |
string | Accessor for raw page information. |
string | Accessor for plain text version of the page. |
string | getCookieValue(string host, string path, string name) Reads the most specific cookie value from the browser cookies. |
string | getCurrentCookieValue(string name) Reads the current cookies for the current URL. |
string/boolean | getField(string name) Accessor for a form element value within the page. |
string/boolean | getFieldById(string/integer id) Accessor for a form element value within the page. |
integer/string/boolean | Accessor for current frame focus. |
array | Accessor for a breakdown of the frameset. |
string | Accessor for raw header information. |
string | Accessor for current MIME type. |
string | getRealm() Accessor for last Authentication realm. |
array | Accessor for a list of all relative links. |
string | Accessor for raw bytes sent down the wire. |
integer | Accessor for last response code. |
string | getTitle() Accessor for parsed title. |
string | Accessor for last error. |
string | getUrl() Accessor for current URL of page or frame if focused. |
boolean | head(string/SimpleUrl url, hash/SimpleFormEncoding parameters) Fetches the page content with a HEAD request. |
void | Disables frames support. |
boolean | isLink(string label) Tests to see if a link is present by label. |
boolean | isLinkById(string id) Tests to see if a link is present by ID attribute. |
string | post(string/SimpleUrl url, hash/SimpleFormEncoding parameters) Fetches the page content with a POST request. |
void | restart(string/integer date) Removes expired and temporary cookies as if the browser was closed and re-opened. |
string/boolean | retry() Equivalent to hitting the retry button on the browser. |
void | setConnectionTimeout(integer timeout) Sets the socket timeout for opening a connection. |
void | setCookie(string name, string value, string host, string path, string expiry) Sets an additional cookie. |
boolean | setField(string name, string value) Sets all form fields with that name. |
boolean | setFieldById(string/integer id, string value) Sets all form fields with that id attribute. |
boolean | setFrameFocus(string name) Sets the focus by name. |
boolean | setFrameFocusByIndex(integer choice) Sets the focus by index. |
void | setMaximumNestedFrames(integer max) Sets the maximum number of nesting of framed pages within a framed page to prevent loops. |
void | setMaximumRedirects(integer max) Sets the maximum number of redirects before a page will be loaded anyway. |
string/boolean | submitFormById(string id) Submits a form by the ID. |
void | Enables frames support. |
void | useProxy(string proxy, string username, string password) Sets proxy to use on all requests for when testing from behind a firewall. |
public SimpleBrowser()
Starts with a fresh browser with no cookie or any other state information. The exception is that a default proxy will be set up if specified in the options.
public void addHeader(string header)
Adds a header to every fetch.
public void ageCookies(integer interval)
Ages the cookies by the specified time.
public boolean authenticate(string username, string password)
Retries a request after setting the authentication for the current realm.
public boolean back()
Equivalent to hitting the back button on the browser. The browser history is unchanged on failure.
public void clearFrameFocus()
Clears the frame focus. All frames will be searched for content.
public string/boolean clickImage(string label, integer x, integer y, hash additional)
Clicks the submit image by some kind of label. Usually the alt tag or the nearest equivalent. The owning form will be submitted by this. Clicking outside of the boundary of the coordinates will result in a failure.
public string/boolean clickImageById(integer/string id, integer x, integer y, hash additional)
Clicks the submit image by ID attribute. The owning form will be submitted by this. Clicking outside of the boundary of the coordinates will result in a failure.
public string/boolean clickImageByName(string name, integer x, integer y, hash additional)
Clicks the submit image by the name. Usually the alt tag or the nearest equivalent. The owning form will be submitted by this. Clicking outside of the boundary of the coordinates will result in a failure.
public string/boolean clickLink(string label, integer index)
Follows a link by label. Will click the first link found with this link text by default, or a later one if an index is given. The match ignores case and white space issues.
public string/boolean clickLinkById(string id)
Follows a link by id attribute.
public string/boolean clickSubmit(string label, hash additional)
Clicks the submit button by label. The owning form will be submitted by this.
public string/boolean clickSubmitById(string id, hash additional)
Clicks the submit button by ID attribute of the button itself. The owning form will be submitted by this.
public string/boolean clickSubmitByName(string name, hash additional)
Clicks the submit button by name attribute. The owning form will be submitted by this.
public boolean forward()
Equivalent to hitting the forward button on the browser. The browser history is unchanged on failure.
public string get(string/SimpleUrl url, hash/SimpleFormEncoding parameters)
Fetches the page content with a simple GET request.
public array getAbsoluteUrls()
Accessor for a list of all fixed links in current page.
public string getAuthentication()
Accessor for last Authentication type. Only valid straight after a challenge (401).
public string getContent()
Accessor for raw page information.
public string getContentAsText()
Accessor for plain text version of the page.
public string getCookieValue(string host, string path, string name)
Reads the most specific cookie value from the browser cookies.
public string getCurrentCookieValue(string name)
Reads the current cookies for the current URL.
public string/boolean getField(string name)
Accessor for a form element value within the page. Finds the first match.
public string/boolean getFieldById(string/integer id)
Accessor for a form element value within the page.
public integer/string/boolean getFrameFocus()
Accessor for current frame focus. Will be false if no frame has focus.
public array getFrames()
Accessor for a breakdown of the frameset.
public string getHeaders()
Accessor for raw header information.
public string getMimeType()
Accessor for current MIME type.
public string getRealm()
Accessor for last Authentication realm. Only valid straight after a challenge (401).
public array getRelativeUrls()
Accessor for a list of all relative links.
public string getRequest()
Accessor for raw bytes sent down the wire.
public integer getResponseCode()
Accessor for last response code.
public string getTitle()
Accessor for parsed title.
public string getTransportError()
Accessor for last error.
public string getUrl()
Accessor for current URL of page or frame if focused.
public boolean head(string/SimpleUrl url, hash/SimpleFormEncoding parameters)
Fetches the page content with a HEAD request. Will affect cookies, but will not change the base URL.
public void ignoreFrames()
Disables frames support. Frames will not be fetched and the frameset page will be used instead.
public boolean isLink(string label)
Tests to see if a link is present by label.
public boolean isLinkById(string id)
Tests to see if a link is present by ID attribute.
public string post(string/SimpleUrl url, hash/SimpleFormEncoding parameters)
Fetches the page content with a POST request.
public void restart(string/integer date)
Removes expired and temporary cookies as if the browser was closed and re-opened.
public string/boolean retry()
Equivalent to hitting the retry button on the browser. Will attempt to repeat the page fetch. If there is no history to repeat it will give false.
public void setConnectionTimeout(integer timeout)
Sets the socket timeout for opening a connection.
public void setCookie(string name, string value, string host, string path, string expiry)
Sets an additional cookie. If a cookie has the same name and path it is replaced.
public boolean setField(string name, string value)
Sets all form fields with that name.
public boolean setFieldById(string/integer id, string value)
Sets all form fields with that id attribute.
public boolean setFrameFocus(string name)
Sets the focus by name.
public boolean setFrameFocusByIndex(integer choice)
Sets the focus by index. The integer index starts from 1.
public void setMaximumNestedFrames(integer max)
Sets the maximum number of nesting of framed pages within a framed page to prevent loops.
public void setMaximumRedirects(integer max)
Sets the maximum number of redirects before a page will be loaded anyway.
public string/boolean submitFormById(string id)
Submits a form by the ID.
public void useFrames()
Enables frames support. Frames will be fetched from now on.
public void useProxy(string proxy, string username, string password)
Sets proxy to use on all requests for when testing from behind a firewall. Set URL to false to disable.
Simulated web browser. This is an aggregate of the user agent, the HTML parsing, request history and the last header set.