Documentation
¶
Overview ¶
A Selenium web driver library written in Go.
Index ¶
- Constants
- Variables
- func IsCommunicationError(err error) bool
- func IsInvalidURLError(err error) bool
- func IsMarshallingError(err error) bool
- func IsSessionIDError(err error) bool
- func IsUnmarshallingError(err error) bool
- type AcceptAlertResponse
- type AddCookieResponse
- type AlertTextResponse
- type AllCookiesResponse
- type BackResponse
- type Browser
- type By
- type Capabilities
- type CloseWindowResponse
- type CommunicationError
- type Cookie
- type CookieResponse
- type CreateSessionCapabilities
- type CreateSessionResponse
- type CurrentURLResponse
- type DeleteCookieResponse
- type DeleteSessionResponse
- type Dimensions
- type DismissAlertResponse
- type Element
- type ElementAttributeResponse
- type ElementCSSValueResponse
- type ElementClearResponse
- type ElementClickResponse
- type ElementEnabledResponse
- type ElementRectangleResponse
- type ElementSelectedResponse
- type ElementSendKeysResponse
- type ElementTagNameResponse
- type ElementTextResponse
- type ErrorResponse
- type ExecuteScriptResponse
- type ForwardResponse
- type GoResponse
- type InvalidURLError
- type MarshallingError
- type MaximizeWindowResponse
- type PageSourceResponse
- type Rectangle
- type RefreshResponse
- type ScreenshotResponse
- type SendAlertTextResponse
- type SessionIDError
- type SessionStatusResponse
- type SetSessionTimeoutResponse
- type SetWindowSizeResponse
- type SwitchToFrameResponse
- type SwitchToParentFrameResponse
- type SwitchToWindowResponse
- type Timeout
- type TitleResponse
- type UnmarshallingError
- type Until
- type WebDriver
- type WindowHandleResponse
- type WindowHandlesResponse
- type WindowSizeResponse
Constants ¶
const ( UnidentifiedKey = string('\uE000') CancelKey = string('\uE001') HelpKey = string('\uE002') BackspaceKey = string('\uE003') TabKey = string('\uE004') ClearKey = string('\uE005') ReturnKey = string('\uE006') EnterKey = string('\uE007') ShiftKey = string('\uE008') ControlKey = string('\uE009') AltKey = string('\uE00A') PauseKey = string('\uE00B') EscapeKey = string('\uE00C') SpaceKey = string('\uE00D') PageUpKey = string('\uE00E') PageDownKey = string('\uE00F') EndKey = string('\uE010') HomeKey = string('\uE011') ArrowLeftKey = string('\uE012') ArrowUpKey = string('\uE013') ArrowRightKey = string('\uE014') ArrowDownKey = string('\uE015') InsertKey = string('\uE016') DeleteKey = string('\uE017') SemiColonKey = string('\uE018') EqualsKey = string('\uE019') AsteriskKey = string('\uE024') PlusKey = string('\uE025') CommaKey = string('\uE026') MinusKey = string('\uE027') PeriodKey = string('\uE028') ForwardSlashKey = string('\uE029') F1Key = string('\uE031') F2Key = string('\uE032') F3Key = string('\uE033') F4Key = string('\uE034') F5Key = string('\uE035') F6Key = string('\uE036') F7Key = string('\uE037') F8Key = string('\uE038') F9Key = string('\uE039') F10Key = string('\uE03A') F11Key = string('\uE03B') F12Key = string('\uE03C') MetaKey = string('\uE03D') ZenkakuHankakuKey = string('\uE040') )
Keyboard keys converted from the ASCII code.
const ( ElementNotSelectable = "element not selectable" ElementNotInteractable = "element not interactable" InsecureCertificate = "insecure certificate" InvalidArgument = "invalid argument" InvalidCookieDomain = "invalid cookie domain" InvalidCoordinates = "invalid coordinates" InvalidElementState = "invalid element state" InvalidSelector = "invalid selector" InvalidSessionID = "invalid session id" JavascriptError = "javascript error" MoveTargetOutOfBounds = "move target out of bounds" NoSuchAlert = "no such alert" NoSuchCookie = "no such cookie" NoSuchElement = "no such element" NoSuchFrame = "no such frame" NoSuchWindow = "no such window" ScriptTimeout = "script timeout" SessionNotCreated = "session not created" StaleElementReference = "stale element reference" TimeoutError = "timeout" UnableToSetCookie = "unable to set cookie" UnableToCaptureScreen = "unable to capture screen" UnexpectedAlertOpen = "unexpected alert open" UnknownCommand = "unknown command" UnknownError = "unknown error" UnknownMethod = "unknown method" UnsupportedOperation = "unsupported operation" )
Error codes that are returned from Selenium. Infer that the type of the error returned is CommunicationError, then do a comparison on the err.Response.State field to one of the below constants.
Variables ¶
var WaitTimeoutError error = errors.New("wait action timed out")
WaitTimeoutError is returned when a Wait call has timed out.
Functions ¶
func IsCommunicationError ¶
IsCommunicationError checks whether an error is a selenium communication error.
func IsInvalidURLError ¶
IsInvalidURLError checks whether an error is due to the URL being incorrectly formatted.
func IsMarshallingError ¶
IsMarshallingError checks whether an error is a marshalling error.
func IsSessionIDError ¶
IsSessionIDError checks whether an error is due to a session ID not being set.
func IsUnmarshallingError ¶
IsUnmarshallingError checks whether an error is a selenium unmarshalling error.
Types ¶
type AcceptAlertResponse ¶
type AcceptAlertResponse struct {
State string
}
AcceptAlertResponse is the response returned from calling the AcceptAlert method.
type AddCookieResponse ¶
type AddCookieResponse struct {
State string
}
AddCookieResponse is the result returned from calling the AddCookie method.
type AlertTextResponse ¶
AlertTextResponse is the response returned from calling the AlertText method.
type AllCookiesResponse ¶
AllCookiesResponse is the response returned from the AllCookies method.
type BackResponse ¶
type BackResponse struct {
State string
}
BackResponse is the response returned from the Back call.
type Browser ¶
type Browser interface {
BrowserName() string
}
Browser defines a supported selenium enabled browser.
func AndroidBrowser ¶
func AndroidBrowser() Browser
AndroidBrowser returns an Android browser object.
func FirefoxBrowser ¶
func FirefoxBrowser() Browser
FirefoxBrowser returns a Firefox browser object.
func HTMLUnitBrowser ¶
func HTMLUnitBrowser() Browser
HTMLUnitBrowser returns a HTMLUnit browser object.
func InternetExplorerBrowser ¶
func InternetExplorerBrowser() Browser
InternetExplorerBrowser returns an IE browser object.
type By ¶
type By interface { // Type is the type of by (i.e. id, xpath, class, name, index). Type() string // Value is the actual value to retrieve something by (i.e. #test, 1). Value() interface{} }
By is an interface that defines what all 'ByX' methods must return.
func ByCSSSelector ¶
ByCSSSelector accepts a CSS selector (i.e. ul#id > a) for use in the FindElement(s) functions.
func ByIndex ¶
ByIndex accepts an integer that represents what the index of an element is and returns the appropriate By implementation.
func ByLinkText ¶
ByLinkText is used to find an anchor element by its innerText.
func ByPartialLinkText ¶
ByPartialLinkText works the same way as ByLinkText but performs a search where the link text contains the string passed in instead of a full match.
func ByXPath ¶
ByXPath utilises the xpath to find elements (see http://www.guru99.com/xpath-selenium.html).
type Capabilities ¶
type Capabilities struct {
// contains filtered or unexported fields
}
Capabilities represents the capabilities defined in the W3C specification. The main capability is the browser, which can be set by calling one of the \wBrowser\(\) methods.
func (*Capabilities) Browser ¶
func (c *Capabilities) Browser() Browser
Browser yields the browser capability assigned to the current Capabilities object..
func (*Capabilities) SetBrowser ¶
func (c *Capabilities) SetBrowser(b Browser)
SetBrowser sets the browser capability to be one of the allowed browsers.
type CloseWindowResponse ¶
CloseWindowResponse is the response returned from the CloseWindow() method. As per the W3C specification, it yields all of the available window handles minus the active one that closes as a result of the CloseWindow() call.
type CommunicationError ¶
type CommunicationError struct { Response *ErrorResponse // contains filtered or unexported fields }
CommunicationError is the result of a communication failure between this library and the WebDriver API.
func (CommunicationError) Error ¶
func (c CommunicationError) Error() string
Error returns a formatted communication error string.
type Cookie ¶
type Cookie struct { Name string `json:"name"` Value string `json:"value"` Path string `json:"path"` Domain string `json:"domain"` SecureOnly bool `json:"secure"` HTTPOnly bool `json:"httpOnly"` }
Cookie represents a browser cookie.
type CookieResponse ¶
CookieResponse is the response returned from the Cookie method.
type CreateSessionCapabilities ¶
type CreateSessionCapabilities struct { AcceptInsecureCerts bool `json:"acceptSslCerts"` BrowserName string `json:"browserName"` BrowserVersion string `json:"browserVersion"` PlatformName string `json:"platformVersion"` }
CreateSessionCapabilities is a summarisation of the capabilities returned from the CreateSession method.
type CreateSessionResponse ¶
type CreateSessionResponse struct { Capabilities CreateSessionCapabilities `json:"value"` SessionID string `json:"sessionId"` }
CreateSessionResponse is the response returned from the API when the CreateSession() method does not throw an error.
type CurrentURLResponse ¶
CurrentURLResponse is the response returned from the GET Url call.
type DeleteCookieResponse ¶
type DeleteCookieResponse struct {
State string
}
DeleteCookieResponse is the result returned from calling the DeleteCookie method.
type DeleteSessionResponse ¶
type DeleteSessionResponse struct { State string `json:"state"` SessionID string `json:"sessionId"` }
DeleteSessionResponse is the response returned from the API when the DeleteSession() method does not thrown an error.
type Dimensions ¶
Dimensions is a type that is both returned and accept by functions. It is usually only used for the window size components.
type DismissAlertResponse ¶
type DismissAlertResponse struct {
State string
}
DismissAlertResponse is the response returned from calling the DismissAlert method.
type Element ¶
type Element interface { // ID is the assigned ID for the element returned from the Selenium driver. ID() string // Selected gets whether or not the current element is selected. This only // makes sense for inputs such as radio buttons and checkboxes. Selected() (*ElementSelectedResponse, error) // Attribute retrieves an attribute (i.e. href, class) of the current // active element. Attribute(att string) (*ElementAttributeResponse, error) // CSSValue retrieves a CSS property associated with the current element. // As an example, this could be the 'background' or 'font-family' properties. CSSValue(prop string) (*ElementCSSValueResponse, error) // Text gets the value of element.innerText for the current element. Text() (*ElementTextResponse, error) // TagName gets the HTML element name (i.e. p, div) of the currently selected // element. TagName() (*ElementTagNameResponse, error) // Rectangle gets the dimensions and co-ordinates of the currently selected // element. Rectangle() (*ElementRectangleResponse, error) // Enabled gets whether or not the current selected elemented is enabled. Enabled() (*ElementEnabledResponse, error) // Click clicks the currently selected element. Please note, you may have to // implement your own wait to ensure the page actually navigates. This is due to // Selenium having no idea whether or not your click will be interrupted by JS. // Alternatively, you can use the WaitUntil(TitleEquals("title"), 20) to // automatically wait until the page title has changed. Click() (*ElementClickResponse, error) // Clear clears the currently selected element according to the specification. Clear() (*ElementClearResponse, error) // SendKeys sends a set of keystrokes to the currently selected element. SendKeys(keys string) (*ElementSendKeysResponse, error) }
Element is an interface which specifies what all WebDriver elements must do. Any requests which involve this element (i.e. FindElements that are children of the current element) will be specified. Anything not related will exist within the WebDriver interface/implementation.
type ElementAttributeResponse ¶
ElementAttributeResponse is the response returned from the Attribute call.
type ElementCSSValueResponse ¶
ElementCSSValueResponse is the response returned when the CSSValue method is called on an Element implementation.
type ElementClearResponse ¶
type ElementClearResponse struct {
State string
}
ElementClearResponse is the response returned from calling the Clear method.
type ElementClickResponse ¶
type ElementClickResponse struct {
State string
}
ElementClickResponse is the response returned from calling the Click method.
type ElementEnabledResponse ¶
ElementEnabledResponse is the response returned from calling the Enabled method.
type ElementRectangleResponse ¶
ElementRectangleResponse is the response returned from calling the Rectangle method.
type ElementSelectedResponse ¶
ElementSelectedResponse is the response returned from the Selected() call. The result /should/ always be successfully returned unless there is a server error.
type ElementSendKeysResponse ¶
type ElementSendKeysResponse struct {
State string
}
ElementSendKeysResponse is the response returned from calling the SendKeys method.
type ElementTagNameResponse ¶
ElementTagNameResponse is the response returned from calling the TagName method.
type ElementTextResponse ¶
ElementTextResponse is the response returned from calling the Text method.
type ErrorResponse ¶
ErrorResponse is what is returned from the Selenium API when an error occurs.
type ExecuteScriptResponse ¶
ExecuteScriptResponse is the response returned from calling the ExecuteScript method.
type ForwardResponse ¶
type ForwardResponse struct {
State string
}
ForwardResponse is the response returned from the Forward call.
type GoResponse ¶
type GoResponse struct {
State string
}
GoResponse is the response returned from the selenium web driver when calling the Go() call. Unfortunately, the W3C specification defines that the response should only be whether the call succeeded or not. Should there be any redirects they will not be catered for in this response. Should you expect any redirects to happen, call the CurrentURL() method.
type InvalidURLError ¶
type InvalidURLError string
InvalidURLError is an error that is returned whenever a URL is not correctly formatted.
func (InvalidURLError) Error ¶
func (i InvalidURLError) Error() string
Error returns the formatted invalid error string.
type MarshallingError ¶
type MarshallingError struct {
// contains filtered or unexported fields
}
MarshallingError is an error that is returned when a json.Marshal error occurs.
func (MarshallingError) Error ¶
func (m MarshallingError) Error() string
Error returns a formatted marshalling error string.
type MaximizeWindowResponse ¶
type MaximizeWindowResponse struct {
State string
}
MaximizeWindowResponse is the response that is returned from increasing the browser to match the viewport.
type PageSourceResponse ¶
PageSourceResponse is the response returned from calling the PageSource method.
type Rectangle ¶
type Rectangle struct { Dimensions X int `json:"x"` Y int `json:"y"` }
Rectangle repsents an elements size and position on the page.
type RefreshResponse ¶
type RefreshResponse struct {
State string
}
RefreshResponse is the response returned from the Refresh call.
type ScreenshotResponse ¶
ScreenshotResponse is the response returned from the Screenshot and ScreenshotElement methods.
func (*ScreenshotResponse) ImageBytes ¶
func (s *ScreenshotResponse) ImageBytes() ([]byte, error)
ImageBytes is a helpful function for decoding the base64 encoded image URL.
type SendAlertTextResponse ¶
type SendAlertTextResponse struct {
State string
}
SendAlertTextResponse is the response returned from calling the SendAlertText method.
type SessionIDError ¶
type SessionIDError string
SessionIDError is an error that is returned when the session id is invalid. This value will contain the method that the session error occurred in.
func (SessionIDError) Error ¶
func (s SessionIDError) Error() string
Error returns a formatted session error string.
type SessionStatusResponse ¶
type SessionStatusResponse struct {
State string
}
SessionStatusResponse is the response returned from the API when the SessionStatus() method is called.
type SetSessionTimeoutResponse ¶
type SetSessionTimeoutResponse struct {
State string
}
SetSessionTimeoutResponse is the response returned from the API when the SetSessionTimeoutResponse() method is called.
type SetWindowSizeResponse ¶
type SetWindowSizeResponse struct {
State string
}
SetWindowSizeResponse is the response that is returned from setting the window size of the current top level browsing context.
type SwitchToFrameResponse ¶
type SwitchToFrameResponse struct {
State string
}
SwitchToFrameResponse is the response returned from the SwitchToFrame() method. For now, according to the specification, it only returns a state.
type SwitchToParentFrameResponse ¶
type SwitchToParentFrameResponse struct {
State string
}
SwitchToParentFrameResponse represents the response from attempting to switch the top level browsing context to the parent of the current top level browsing context.
type SwitchToWindowResponse ¶
type SwitchToWindowResponse struct { }
SwitchToWindowResponse is the response returned from the SwitchToWindow() method. You can verify that this result is correct by calling the WindowHandle() method. The two should match.
type Timeout ¶
type Timeout interface { // Type is the type of the timeout that is being used. Type() string // Timeout is the timeout in milliseconds. Timeout() int }
Timeout is an interface which specifies what all timeout requests must follow.
func SessionImplicitWaitTimeout ¶
SessionImplicitWaitTimeout creates an appropriate timeout implementation for the session implicit wait timeout.
func SessionPageLoadTimeout ¶
SessionPageLoadTimeout creates an appropriate Timeout implementation for the page load timeout.
func SessionScriptTimeout ¶
SessionScriptTimeout creates an appropriate Timeout implementation for the script timeout.
type TitleResponse ¶
TitleResponse is the response returned from the Title call.
type UnmarshallingError ¶
type UnmarshallingError struct {
// contains filtered or unexported fields
}
UnmarshallingError is the result of an unmarshalling failure of a JSON string.
func (UnmarshallingError) Error ¶
func (u UnmarshallingError) Error() string
Error returns a formatted unmarshalling error string.
type Until ¶
Until represents a function that will be continuously repeated until it succeeds or a timeout is reached.
func UntilElementPresent ¶
UntilElementPresent attempts to locate an element on the page. It is determined as existing if the state is 'Success' and the error is nil.
func UntilURLIs ¶
UntilURLIs checks whether or not the page's URL has changed.
type WebDriver ¶
type WebDriver interface { // DriverURL returns the URL where the W3C compliant web driver is hosted. DriverURL() string // CreateSession creates a session in the remote driver with the // desired capabilities. CreateSession() (*CreateSessionResponse, error) // DeleteSession deletes the current session associated with the web driver. DeleteSession() (*DeleteSessionResponse, error) // SessionStatus gets the status about whether a remove end is in a state // which it can create new sessions. SessionStatus() (*SessionStatusResponse, error) // SetSessionTimeout sets a timeout for one of the 3 options. // Call SessionScriptTimeout() to generate a script timeout. // Call SessionPageLoadTimeout() to generate a page load timeout. // Call SessionImplicitWaitTimeout() to generate an implicit wait timeout. SetSessionTimeout(to Timeout) (*SetSessionTimeoutResponse, error) // Go forces the browser to perform a GET request on a URL. Go(url string) (*GoResponse, error) // CurrentURL returns the current URL of the top level browsing context. CurrentURL() (*CurrentURLResponse, error) // Back instructs the web driver to go one step back in the page history. Back() (*BackResponse, error) // Forward instructs the web driver to go one step forward in the page history. Forward() (*ForwardResponse, error) // Refresh instructs the web driver to refresh the page that it is currently on. Refresh() (*RefreshResponse, error) // Title gets the title of the current page of the web driver. Title() (*TitleResponse, error) // WindowHandle retrieves the current active browsing string for the current session. WindowHandle() (*WindowHandleResponse, error) // CloseWindow closes the current active window (see WindowHandle() for what // window that will be). CloseWindow() (*CloseWindowResponse, error) // SwitchToWindow switches the current browsing context to a specified window // handle. SwitchToWindow(handle string) (*SwitchToWindowResponse, error) // WindowHandles gets all of the window handles for the current session. // To retrieve the currently active window handle, see WindowHandle(). WindowHandles() (*WindowHandlesResponse, error) // SwitchToFrame switches to a frame determined by the "by" parameter. // You can use ByIndex to find the frame to switch to. Any other // By implementation will yield an InvalidByParameter error. SwitchToFrame(by By) (*SwitchToFrameResponse, error) // SwitchToParentFrame switches to the parent of the current top level // browsing context. SwitchToParentFrame() (*SwitchToParentFrameResponse, error) // WindowSize retrieves the current browser window size for the // active session. WindowSize() (*WindowSizeResponse, error) // SetWindowSize sets the current browser window size for the active // session. SetWindowSize(dimensions *Dimensions) (*SetWindowSizeResponse, error) // Maximize increases the current browser window to its maximum size. MaximizeWindow() (*MaximizeWindowResponse, error) // FindElement finds an element via a By implementation (i.e. CSS selector, // x-path). Attempting to find via index will result in an argument error // being thrown. FindElement(by By) (Element, error) // FindElements works the same way as FindElement but can return more than // one result. FindElements(by By) ([]Element, error) // PageSource retrieves the outerHTML value of the current URL. PageSource() (*PageSourceResponse, error) // ExecuteScript executes a Javascript script on the currently active // page. ExecuteScript(script string) (*ExecuteScriptResponse, error) // ExecuteScriptAsync executes a Javascript script asynchronously on the // currently active page. If you do not have experience with this call, // there is an example below. // // The async handler runs on the concept of a callback; meaning it will run // your code asynchronously and if it completes, will call the callback. // // Selenium helpfully provides a callback function which is passed in // to the 'arguments' array that you can access within your script. The // callback function is always the LAST element of the array. You can // access it like the below: // var callback = arguments[arguments.length - 1]; // The callback function also accepts one argument as a parameter, this // can be anything and will be assigned to the Response property of // ExecuteScriptResponse. // // An example: // var callback = arguments[arguments.length - 1]; // doLongWindedTask(); // callback(); ExecuteScriptAsync(script string) (*ExecuteScriptResponse, error) // AllCookies returns all cookies associated with the active URL of the // current browsing context. AllCookies() (*AllCookiesResponse, error) // Cookie gets a single named cookie associated with the active URL of the // current browsing context. Cookie(name string) (*CookieResponse, error) // AddCookie adds a cookie to the current browsing context. AddCookie(c *Cookie) (*AddCookieResponse, error) // DeleteCookie deletes a cookie from the current browsing session. If name // is passed as an empty string, all cookies for the current address will // be deleted. DeleteCookie(name string) (*DeleteCookieResponse, error) // DismissAlert dismisses an alert if there is one present. If not, it will // throw an error. DismissAlert() (*DismissAlertResponse, error) // AcceptAlertResponse accepts an alert if there is one present. If not, // it will throw an error. AcceptAlert() (*AcceptAlertResponse, error) // AlertText gets the text associated with the current alert. If there is // not an alert, it will throw an error. AlertText() (*AlertTextResponse, error) // SendAlertText enters the text specified into the value box. // // If the prompt is of type 'alert' or 'confirm', a communication error // with code 'element not interactable' will be returned. // // If the prompt is anything other than 'prompt', a communication error with // code 'unsupported operation' will be returned. SendAlertText(text string) (*SendAlertTextResponse, error) // Screenshot takes a screenshot of the window of the current top level // browsing context. Screenshot() (*ScreenshotResponse, error) // Wait repeats an action until the action yields a valid result or // until the timeout is reached. If the timeout is reached without // the until function returning a satisfactory result, this method // will return false. // // time.Sleep will be called with the sleep parameter after every // u iteration. Wait(u Until, timeout time.Duration, sleep time.Duration) bool }
WebDriver is an interface which adheres to the W3C specification for WebDrivers (https://w3c.github.io/webdriver/webdriver-spec.html).
func NewSeleniumWebDriver ¶
func NewSeleniumWebDriver(serviceURL string, capabilities Capabilities) (WebDriver, error)
NewSeleniumWebDriver creates a new instance of a Selenium web driver with a service URL (usually http://domain:port/wd/hub) and a Capabilities object. This method will return validation errors if the Selenium URL is invalid or the required capabilities (BrowserName) are not set.
type WindowHandleResponse ¶
WindowHandleResponse is the response returned from the WindowHandle() method. The handle is the current active window. Should you switch windows, any value returned prior to that call will be invalid.
type WindowHandlesResponse ¶
WindowHandlesResponse is the response returned from the WindowHandles() method. This is essentially an array of available window handlers that aren't neccessarily active.
type WindowSizeResponse ¶
type WindowSizeResponse struct { State string `json:"state"` Dimensions Dimensions `json:"value"` }
WindowSizeResponse is the response returned from calling the WindowSize method. The definitions are in CSS pixels.
Source Files
¶
- api_service.go
- capabilities.go
- doc.go
- errors.go
- remote_driver.go
- remote_driver_alert.go
- remote_driver_command.go
- remote_driver_cookie.go
- remote_driver_document.go
- remote_driver_element.go
- remote_driver_helpers.go
- remote_driver_navigation.go
- remote_driver_screenshot.go
- remote_driver_session.go
- remote_element.go
- web_driver.go