selenium

package module
v0.0.0-...-29c8173 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 29 Imported by: 0

README

The most complete, best-tested WebDriver client for Go

GoDoc Travis Go Report Card

About

This is a WebDriver client for Go. It supports the WebDriver protocol and has been tested with various versions of Selenium WebDriver, Firefox and Geckodriver, and Chrome and ChromeDriver,

selenium is currently maintained by Eric Garrido (@minusnine).

Installing

Run

go get -t -d github.com/tebeka/selenium

to fetch the package.

The package requires a working WebDriver installation, which can include recent versions of a web browser being driven by Selenium WebDriver.

Downloading Dependencies

We provide a means to download the ChromeDriver binary, the Firefox binary, the Selenium WebDriver JARs, and the Sauce Connect proxy binary. This is primarily intended for testing.

$ cd vendor
$ go run init.go --alsologtostderr  --download_browsers --download_latest
$ cd ..

Re-run this periodically to get up-to-date versions of these binaries.

Documentation

The API documentation is at https://godoc.org/github.com/tebeka/selenium. See the example and unit tests(for sauce, selenium and service) for better usage information.

Known Issues

Any issues are usually because the underlying browser automation framework has a bug or inconsistency. Where possible, we try to cover up these underlying problems in the client, but sometimes workarounds require higher-level intervention.

Please feel free to file an issue if this client doesn't work as expected.

Below are known issues that affect the usage of this API. There are likely others filed on the respective issue trackers.

Selenium 2

No longer supported.

Selenium 3
  1. Selenium 3 NewSession does not implement the W3C-specified parameters.
Geckodriver (Standalone)
  1. Geckodriver does not support the Log API because it hasn't been defined in the spec yet.
  2. Firefox via Geckodriver (and also through Selenium) doesn't handle clicking on an element.
  3. Firefox via Geckodriver doesn't handle sending control characters without appending a terminating null key.
Chromedriver
  1. Headless Chrome does not support running extensions.

Breaking Changes

There are a number of upcoming changes that break backward compatibility in an effort to improve and adapt the existing API. They are listed here:

22 August 2017

The Version constant was removed as it is unused.

18 April 2017

The Log method was changed to accept a typed constant for the type of log to retrieve, instead of a raw string. The return value was also changed to provide a more idiomatic type.

Hacking

Patches are encouraged through GitHub pull requests. Please ensure that:

  1. A test is added for anything more than a trivial change and that the existing tests pass. See below for instructions on setting up your test environment.

  2. Please ensure that gofmt has been run on the changed files before committing. Install a pre-commit hook with the following command:

    $ ln -s ../../misc/git/pre-commit .git/hooks/pre-commit

See the issue tracker for features that need implementing.

Testing Locally

Install xvfb and Java if they is not already installed, e.g.:

sudo apt-get install xvfb openjdk-11-jre

Run the tests:

$ go test
  • There is one top-level test for each of:

    1. Chromium and ChromeDriver.
    2. A new version of Firefox and Selenium 3.
    3. HTMLUnit, a Java-based lightweight headless browser implementation.
    4. A new version of Firefox directly against Geckodriver.

    There are subtests that are shared between both top-level tests.

  • To run only one of the top-level tests, pass one of:

    • -test.run=TestFirefoxSelenium3,
    • -test.run=TestFirefoxGeckoDriver,
    • -test.run=TestHTMLUnit, or
    • -test.run=TestChrome.

    To run a specific subtest, pass -test.run=Test<Browser>/<subtest> as appropriate. This flag supports regular expressions.

  • If the Chrome or Firefox binaries, the Selenium JAR, the Geckodriver binary, or the ChromeDriver binary cannot be found, the corresponding tests will be skipped.

  • The binaries and JAR under test can be configured by passing flags to go test. See the available flags with go test --arg --help.

  • Add the argument -test.v to see detailed output from the test automation framework.

Testing With Docker

To ensure hermeticity, we also have tests that run under Docker. You will need an installed and running Docker system.

To run the tests under Docker, run:

$ go test --docker

This will create a new Docker container and run the tests in it. (Note: flags supplied to this invocation are not curried through to the go test invocation within the Docker container).

For debugging Docker directly, run the following commands:

$ docker build -t go-selenium testing/
$ docker run --volume=$(pwd):/code --workdir=/code -it go-selenium bash
root@6c7951e41db6:/code# testing/docker-test.sh
... lots of testing output ...
Testing With Sauce Labs

Tests can be run using a browser located in the cloud via Sauce Labs.

To run the tests under Sauce, run:

$ go test --test.run=TestSauce --test.timeout=20m \
  --experimental_enable_sauce \
  --sauce_user_name=[username goes here] \
  --sauce_access_key=[access key goes here]

The Sauce access key can be obtained via the Sauce Labs user settings page.

Test results can be viewed through the Sauce Labs Dashboard.

License

This project is licensed under the MIT license.

Documentation

Index

Constants

View Source
const (
	// DefaultURLPrefix is the default HTTP endpoint that offers the WebDriver API.
	DefaultURLPrefix = "http://127.0.0.1:4444/wd/hub"

	// DefaultWaitInterval is the default polling interval for selenium.Wait
	// function.
	DefaultWaitInterval = 100 * time.Millisecond

	// DefaultWaitTimeout is the default timeout for selenium.Wait function.
	DefaultWaitTimeout = 60 * time.Second
)
View Source
const (
	ByID              = "id"
	ByXPATH           = "xpath"
	ByLinkText        = "link text"
	ByPartialLinkText = "partial link text"
	ByName            = "name"
	ByTagName         = "tag name"
	ByClassName       = "class name"
	ByCSSSelector     = "css selector"
)

Methods by which to find elements.

View Source
const (
	NullKey       = 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')
	LeftArrowKey  = string('\ue012')
	UpArrowKey    = string('\ue013')
	RightArrowKey = string('\ue014')
	DownArrowKey  = string('\ue015')
	InsertKey     = string('\ue016')
	DeleteKey     = string('\ue017')
	SemicolonKey  = string('\ue018')
	EqualsKey     = string('\ue019')
	Numpad0Key    = string('\ue01a')
	Numpad1Key    = string('\ue01b')
	Numpad2Key    = string('\ue01c')
	Numpad3Key    = string('\ue01d')
	Numpad4Key    = string('\ue01e')
	Numpad5Key    = string('\ue01f')
	Numpad6Key    = string('\ue020')
	Numpad7Key    = string('\ue021')
	Numpad8Key    = string('\ue022')
	Numpad9Key    = string('\ue023')
	MultiplyKey   = string('\ue024')
	AddKey        = string('\ue025')
	SeparatorKey  = string('\ue026')
	SubstractKey  = string('\ue027')
	DecimalKey    = string('\ue028')
	DivideKey     = 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')
)

Special keyboard keys, for SendKeys.

View Source
const (
	// Direct connection - no proxy in use.
	Direct ProxyType = "direct"
	// Manual proxy settings configured, e.g. setting a proxy for HTTP, a proxy
	// for FTP, etc.
	Manual = "manual"
	// Autodetect proxy, probably with WPAD
	Autodetect = "autodetect"
	// System settings used.
	System = "system"
	// PAC - Proxy autoconfiguration from a URL.
	PAC = "pac"
)
View Source
const (
	MousePointer PointerType = "mouse"
	PenPointer               = "pen"
	TouchPointer             = "touch"
)

Variables

View Source
var HTTPClient = &http.Client{}

HTTPClient is the default client to use to communicate with the WebDriver server.

Functions

func Debug

func Debug(b ...bool)

Debug 设置调试模式,打印日志

func DeleteSession

func DeleteSession(urlPrefix, id string) error

DeleteSession deletes an existing session at the WebDriver instance specified by the urlPrefix and the session ID.

func SetLogLevel

func SetLogLevel(level logs.Level)

SetLogLevel 设置日志等级

Types

type Actions

type Actions []map[string]interface{}

Actions stores KeyActions and PointerActions for later execution.

type Capabilities

type Capabilities map[string]interface{}

Capabilities configures both the WebDriver process and the target browsers, with standard and browser-specific options.

func (Capabilities) AddChrome

func (c Capabilities) AddChrome(f chrome.Capabilities)

AddChrome adds Chrome-specific capabilities.

func (Capabilities) AddFirefox

func (c Capabilities) AddFirefox(f firefox.Capabilities)

AddFirefox adds Firefox-specific capabilities.

func (Capabilities) AddLogging

func (c Capabilities) AddLogging(l log.Capabilities)

AddLogging adds logging configuration to the capabilities.

func (Capabilities) AddProxy

func (c Capabilities) AddProxy(p Proxy)

AddProxy adds proxy configuration to the capabilities.

func (Capabilities) SetLogLevel

func (c Capabilities) SetLogLevel(typ log.Type, level log.Level)

SetLogLevel sets the logging level of a component. It is a shortcut for passing a log.Capabilities instance to AddLogging.

type Condition

type Condition func(wd *WebDriver) (bool, error)

Condition is an alias for a type that is passed as an argument for selenium.Wait(cond Condition) (error) function.

type Cookie struct {
	Name     string   `json:"name"`
	Value    string   `json:"value"`
	Path     string   `json:"path"`
	Domain   string   `json:"domain"`
	Secure   bool     `json:"secure"`
	Expiry   uint     `json:"expiry"`
	HTTPOnly bool     `json:"httpOnly"`
	SameSite SameSite `json:"sameSite,omitempty"`
}

Cookie represents an HTTP cookie.

type Entity

type Entity struct {
	*Service

	Prefs map[string]interface{}
	Args  []string
	// contains filtered or unexported fields
}

func New

func New(driverPath, browserPath string, option ...Option) (*Entity, error)

func (*Entity) AddArgument

func (this *Entity) AddArgument(args ...string) *Entity

func (*Entity) Close

func (this *Entity) Close()

func (*Entity) DelArgument

func (this *Entity) DelArgument(arg string) *Entity

func (*Entity) Run

func (this *Entity) Run(f func(w *WebDriver) error, retry ...uint) error

Run 执行

func (*Entity) SetBrowser

func (this *Entity) SetBrowser(b string) *Entity

SetBrowser 设置浏览器,目前只测试了chrome

func (*Entity) SetBrowserPath

func (this *Entity) SetBrowserPath(p string) *Entity

SetBrowserPath 设置浏览器目录

func (*Entity) SetPref

func (this *Entity) SetPref(key string, value interface{}) *Entity

func (*Entity) SetProxy

func (this *Entity) SetProxy(u string) *Entity

func (*Entity) SetUserAgent

func (this *Entity) SetUserAgent(ua string) *Entity

SetUserAgent 设置UserAgent

func (*Entity) SetUserAgentDefault

func (this *Entity) SetUserAgentDefault() *Entity

SetUserAgentDefault 设置UserAgent到默认值

func (*Entity) SetUserAgentRand

func (this *Entity) SetUserAgentRand() *Entity

SetUserAgentRand 设置随机UserAgent

func (*Entity) ShowImg

func (this *Entity) ShowImg(b ...bool) *Entity

ShowImg 是否加载图片

func (*Entity) ShowWindow

func (this *Entity) ShowWindow(b ...bool) *Entity

ShowWindow 显示窗口linux系统无效

func (*Entity) WebDriver

func (this *Entity) WebDriver() (*WebDriver, error)

type Error

type Error struct {
	// Err contains a general error string provided by the server.
	Err string `json:"error"`
	// Message is a detailed, human-readable message specific to the failure.
	Message string `json:"message"`
	// Stacktrace may contain the server-side stacktrace where the error occurred.
	Stacktrace string `json:"stacktrace"`
	// HTTPCode is the HTTP status code returned by the server.
	HTTPCode int
	// LegacyCode is the "Response Status Code" defined in the legacy Selenium
	// WebDriver JSON wire protocol. This code is only produced by older
	// Selenium WebDriver versions, Chromedriver, and InternetExplorerDriver.
	LegacyCode int
}

Error contains information about a failure of a command. See the table of these strings at https://www.w3.org/TR/webdriver/#handling-errors .

This error type is only returned by servers that implement the W3C specification.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

type FrameBuffer

type FrameBuffer struct {
	// Display is the X11 display number that the Xvfb process is hosting
	// (without the preceding colon).
	Display string
	// AuthPath is the path to the X11 authorization file that permits X clients
	// to use the X server. This is typically provided to the client via the
	// XAUTHORITY environment variable.
	AuthPath string
	// contains filtered or unexported fields
}

FrameBuffer controls an X virtual frame buffer running as a background process.

func NewFrameBuffer

func NewFrameBuffer() (*FrameBuffer, error)

NewFrameBuffer starts an X virtual frame buffer running in the background.

This is equivalent to calling NewFrameBufferWithOptions with an empty NewFrameBufferWithOptions.

func NewFrameBufferWithOptions

func NewFrameBufferWithOptions(options FrameBufferOptions) (*FrameBuffer, error)

NewFrameBufferWithOptions starts an X virtual frame buffer running in the background. FrameBufferOptions may be populated to change the behavior of the frame buffer.

func (FrameBuffer) Stop

func (f FrameBuffer) Stop() error

Stop kills the background frame buffer process and removes the X authorization file.

type FrameBufferOptions

type FrameBufferOptions struct {
	// ScreenSize is the option for the frame buffer screen size.
	// This is of the form "{width}x{height}[x{depth}]".  For example: "1024x768x24"
	ScreenSize string
}

FrameBufferOptions describes the options that can be used to create a frame buffer.

type KeyAction

type KeyAction map[string]interface{}

KeyAction represents an activity involving a keyboard key.

func KeyDownAction

func KeyDownAction(key string) KeyAction

KeyDownAction builds a KeyAction which presses and holds the specified key.

func KeyPauseAction

func KeyPauseAction(duration time.Duration) KeyAction

KeyPauseAction builds a KeyAction which pauses for the supplied duration.

func KeyUpAction

func KeyUpAction(key string) KeyAction

KeyUpAction builds a KeyAction press.

type MouseButton

type MouseButton int
const (
	LeftButton MouseButton = iota
	MiddleButton
	RightButton
)

Mouse buttons.

type Option

type Option func(e *Entity) error

type Point

type Point struct {
	X, Y int
}

Point is a 2D point.

type PointerAction

type PointerAction map[string]interface{}

PointerAction represents an activity involving a pointer.

func PointerDownAction

func PointerDownAction(button MouseButton) PointerAction

PointerDownAction PointerDown builds a PointerAction which presses and holds the specified pointer key.

func PointerMoveAction

func PointerMoveAction(duration time.Duration, offset Point, origin PointerMoveOrigin) PointerAction

PointerMoveAction PointerMove builds a PointerAction which moves the pointer.

func PointerPauseAction

func PointerPauseAction(duration time.Duration) PointerAction

PointerPauseAction PointerPause builds a PointerAction which pauses for the supplied duration.

func PointerUpAction

func PointerUpAction(button MouseButton) PointerAction

PointerUpAction PointerUp builds an action which releases the specified pointer key.

type PointerMoveOrigin

type PointerMoveOrigin string

PointerMoveOrigin controls how the offset for the pointer move action is calculated.

const (
	// FromViewport calculates the offset from the viewport at 0,0.
	FromViewport PointerMoveOrigin = "viewport"
	// FromPointer calculates the offset from the current pointer position.
	FromPointer = "pointer"
)

type PointerType

type PointerType string

PointerType is the type of pointer used by StorePointerActions. There are 3 different types according to the WC3 implementation.

type Proxy

type Proxy struct {
	// Type is the type of proxy to use. This is required to be populated.
	Type ProxyType `json:"proxyType"`

	// AutoconfigURL is the URL to be used for proxy auto configuration. This is
	// required if Type is set to PAC.
	AutoconfigURL string `json:"proxyAutoconfigUrl,omitempty"`

	// The following are used when Type is set to Manual.
	//
	// Note that in Firefox, connections to localhost are not proxied by default,
	// even if a proxy is set. This can be overridden via a preference setting.
	FTP           string   `json:"ftpProxy,omitempty"`
	HTTP          string   `json:"httpProxy,omitempty"`
	SSL           string   `json:"sslProxy,omitempty"`
	SOCKS         string   `json:"socksProxy,omitempty"`
	SOCKSVersion  int      `json:"socksVersion,omitempty"`
	SOCKSUsername string   `json:"socksUsername,omitempty"`
	SOCKSPassword string   `json:"socksPassword,omitempty"`
	NoProxy       []string `json:"noProxy,omitempty"`

	// The W3C draft spec includes port fields as well. According to the
	// specification, ports can also be included in the above addresses. However,
	// in the Geckodriver implementation, the ports must be specified by these
	// additional fields.
	HTTPPort  int `json:"httpProxyPort,omitempty"`
	SSLPort   int `json:"sslProxyPort,omitempty"`
	SocksPort int `json:"socksProxyPort,omitempty"`
}

Proxy specifies configuration for proxies in the browser. Set the key "proxy" in Capabilities to an instance of this type.

type ProxyType

type ProxyType string

ProxyType is an enumeration of the types of proxies available.

type SameSite

type SameSite string

SameSite is the type for the SameSite field in Cookie.

const (
	SameSiteNone   SameSite = "None"
	SameSiteLax    SameSite = "Lax"
	SameSiteStrict SameSite = "Strict"
	SameSiteEmpty  SameSite = ""
)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service controls a locally-running Selenium subprocess.

func NewChromeDriverService

func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error)

NewChromeDriverService starts a ChromeDriver instance in the background.

func NewGeckoDriverService

func NewGeckoDriverService(path string, port int, opts ...ServiceOption) (*Service, error)

NewGeckoDriverService starts a GeckoDriver instance in the background.

func NewSeleniumService

func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error)

NewSeleniumService starts a Selenium instance in the background.

func (*Service) FrameBuffer

func (s *Service) FrameBuffer() *FrameBuffer

FrameBuffer returns the FrameBuffer if one was started by the service and nil otherwise.

func (*Service) GetUrl

func (s *Service) GetUrl() string

func (*Service) SetOutput

func (s *Service) SetOutput(out io.Writer) *Service

func (*Service) SetUrl

func (s *Service) SetUrl(u string) error

func (*Service) Stop

func (s *Service) Stop() error

Stop shuts down the WebDriver service, and the X virtual frame buffer if one was started.

type ServiceOption

type ServiceOption func(*Service) error

ServiceOption configures a Service instance.

func ChromeDriver

func ChromeDriver(path string) ServiceOption

ChromeDriver sets the path for Chromedriver for the Selenium Server. This ServiceOption is only useful when calling NewSeleniumService.

func Display

func Display(d, xauthPath string) ServiceOption

Display specifies the value to which set the DISPLAY environment variable, as well as the path to the Xauthority file containing credentials needed to write to that X server.

func GeckoDriver

func GeckoDriver(path string) ServiceOption

GeckoDriver sets the path to the geckodriver binary for the Selenium Server. Unlike other drivers, Selenium Server does not support specifying the geckodriver path at runtime. This ServiceOption is only useful when calling NewSeleniumService.

func HTMLUnit

func HTMLUnit(path string) ServiceOption

HTMLUnit specifies the path to the JAR for the HTMLUnit driver (compiled with its dependencies).

https://github.com/SeleniumHQ/htmlunit-driver/releases

func JavaPath

func JavaPath(path string) ServiceOption

JavaPath specifies the path to the JRE.

func Output

func Output(w io.Writer) ServiceOption

Output specifies that the WebDriver service should log to the provided writer.

func StartFrameBuffer

func StartFrameBuffer() ServiceOption

StartFrameBuffer causes an X virtual frame buffer to start before the WebDriver service. The frame buffer process will be terminated when the service itself is stopped.

This is equivalent to calling StartFrameBufferWithOptions with an empty map.

func StartFrameBufferWithOptions

func StartFrameBufferWithOptions(options FrameBufferOptions) ServiceOption

StartFrameBufferWithOptions causes an X virtual frame buffer to start before the WebDriver service. The frame buffer process will be terminated when the service itself is stopped.

type Size

type Size struct {
	Width, Height int
}

Size is a size of HTML element.

type Status

type Status struct {
	// The following fields are used by Selenium and ChromeDriver.
	Java struct {
		Version string
	}
	Build struct {
		Version, Revision, Time string
	}
	OS struct {
		Arch, Name, Version string
	}

	// The following fields are specified by the W3C WebDriver specification and
	// are used by GeckoDriver.
	Ready   bool
	Message string
}

Status contains information returned by the Status method.

type WebDriver

type WebDriver struct {
	// contains filtered or unexported fields
}

func Chrome

func Chrome(driverPath, browserPath string, option ...Option) (*WebDriver, error)

func NewRemote

func NewRemote(capabilities Capabilities, urlPrefix string) (*WebDriver, error)

NewRemote creates new remote client, this will also start a new session. capabilities provides the desired capabilities. urlPrefix is the URL to the Selenium server, must be prefixed with protocol (http, https, ...).

Providing an empty string for urlPrefix causes the DefaultURLPrefix to be used.

func (*WebDriver) AcceptAlert

func (wd *WebDriver) AcceptAlert() error

func (*WebDriver) ActiveElement

func (wd *WebDriver) ActiveElement() (*WebElement, error)

func (*WebDriver) AddCookie

func (wd *WebDriver) AddCookie(cookie *Cookie) error

func (*WebDriver) AlertText

func (wd *WebDriver) AlertText() (string, error)

func (*WebDriver) Back

func (wd *WebDriver) Back() error

func (*WebDriver) ButtonDown

func (wd *WebDriver) ButtonDown() error

ButtonDown TODO(minusnine): add a test for ButtonDown.

func (*WebDriver) ButtonUp

func (wd *WebDriver) ButtonUp() error

ButtonUp TODO(minusnine): add a test for ButtonUp.

func (*WebDriver) Capabilities

func (wd *WebDriver) Capabilities() (Capabilities, error)

func (*WebDriver) Click

func (wd *WebDriver) Click(button int) error

Click TODO(minusnine): add a test for Click.

func (*WebDriver) Close

func (wd *WebDriver) Close() error

func (*WebDriver) CloseWindow

func (wd *WebDriver) CloseWindow(name string) error

func (*WebDriver) Copy

func (this *WebDriver) Copy() *WebDriver

Copy 复制实例,可以生成多个标签页的实例

func (*WebDriver) CurrentURL

func (wd *WebDriver) CurrentURL() (string, error)

func (*WebDriver) CurrentWindowHandle

func (wd *WebDriver) CurrentWindowHandle() (string, error)

func (*WebDriver) DecodeElement

func (wd *WebDriver) DecodeElement(data []byte) (*WebElement, error)

func (*WebDriver) DecodeElements

func (wd *WebDriver) DecodeElements(data []byte) ([]*WebElement, error)

func (*WebDriver) DeleteAllCookies

func (wd *WebDriver) DeleteAllCookies() error

func (*WebDriver) DeleteCookie

func (wd *WebDriver) DeleteCookie(name string) error

func (*WebDriver) DismissAlert

func (wd *WebDriver) DismissAlert() error

func (*WebDriver) DoubleClick

func (wd *WebDriver) DoubleClick() error

DoubleClick TODO(minusnine): add a test for DoubleClick.

func (*WebDriver) ExecuteScript

func (wd *WebDriver) ExecuteScript(script string, args []interface{}) (interface{}, error)

func (*WebDriver) ExecuteScriptAsync

func (wd *WebDriver) ExecuteScriptAsync(script string, args []interface{}) (interface{}, error)

func (*WebDriver) ExecuteScriptAsyncRaw

func (wd *WebDriver) ExecuteScriptAsyncRaw(script string, args []interface{}) ([]byte, error)

func (*WebDriver) ExecuteScriptRaw

func (wd *WebDriver) ExecuteScriptRaw(script string, args []interface{}) ([]byte, error)

func (*WebDriver) Find

func (this *WebDriver) Find(by, value string) (*WebElement, error)

Find 查找一个元素

func (*WebDriver) FindAll

func (this *WebDriver) FindAll(by, value string) ([]*WebElement, error)

FindAll 查找所有元素

func (*WebDriver) FindElement

func (wd *WebDriver) FindElement(by, value string) (*WebElement, error)

func (*WebDriver) FindElements

func (wd *WebDriver) FindElements(by, value string) ([]*WebElement, error)

func (*WebDriver) FindTag

func (this *WebDriver) FindTag(tag string) (*WebElement, error)

FindTag 查找标签,例如a标签

func (*WebDriver) FindTagAttributes

func (this *WebDriver) FindTagAttributes(tag string) ([]string, error)

FindTagAttributes 查找所有标签的属性Attribute,例如a.href

func (*WebDriver) FindTags

func (this *WebDriver) FindTags(tag string) ([]*WebElement, error)

FindTags 查找所有标签,例如a标签,href在a标签里面

func (*WebDriver) Forward

func (wd *WebDriver) Forward() error

func (*WebDriver) Get

func (wd *WebDriver) Get(url string) error

func (*WebDriver) GetCookie

func (wd *WebDriver) GetCookie(name string) (Cookie, error)

func (*WebDriver) GetCookies

func (wd *WebDriver) GetCookies() ([]Cookie, error)

func (*WebDriver) KeyDown

func (wd *WebDriver) KeyDown(keys string) error

func (*WebDriver) KeyUp

func (wd *WebDriver) KeyUp(keys string) error

func (*WebDriver) Log

func (wd *WebDriver) Log(typ log.Type) ([]log.Message, error)

func (*WebDriver) MaximizeWindow

func (wd *WebDriver) MaximizeWindow(name string) error

func (*WebDriver) MinimizeWindow

func (wd *WebDriver) MinimizeWindow(name string) error

func (*WebDriver) NewSession

func (wd *WebDriver) NewSession() (string, error)

func (*WebDriver) PageSource

func (wd *WebDriver) PageSource() (string, error)

func (*WebDriver) PerformActions

func (wd *WebDriver) PerformActions() error

func (*WebDriver) Quit

func (wd *WebDriver) Quit() error

func (*WebDriver) RangeTags

func (this *WebDriver) RangeTags(tag string, f func(*WebElement) error) error

RangeTags 遍历标签,例如a标签

func (*WebDriver) Refresh

func (wd *WebDriver) Refresh() error

func (*WebDriver) ReleaseActions

func (wd *WebDriver) ReleaseActions() error

func (*WebDriver) ResizeWindow

func (wd *WebDriver) ResizeWindow(name string, width, height int) error

func (*WebDriver) SaveScreenshot

func (wd *WebDriver) SaveScreenshot(filename string) error

SaveScreenshot 保存截图

func (*WebDriver) Screenshot

func (wd *WebDriver) Screenshot() ([]byte, error)

Screenshot 截图信息

func (*WebDriver) SendModifier

func (wd *WebDriver) SendModifier(modifier string, isDown bool) error

func (*WebDriver) SessionID

func (wd *WebDriver) SessionID() string

SessionID returns the current session ID

func (*WebDriver) SetAlertText

func (wd *WebDriver) SetAlertText(text string) error

func (*WebDriver) SetAsyncScriptTimeout

func (wd *WebDriver) SetAsyncScriptTimeout(timeout time.Duration) error

func (*WebDriver) SetImplicitWaitTimeout

func (wd *WebDriver) SetImplicitWaitTimeout(timeout time.Duration) error

func (*WebDriver) SetPageLoadTimeout

func (wd *WebDriver) SetPageLoadTimeout(timeout time.Duration) error

func (*WebDriver) Status

func (wd *WebDriver) Status() (*Status, error)

func (*WebDriver) StoreKeyActions

func (wd *WebDriver) StoreKeyActions(inputID string, actions ...KeyAction)

func (*WebDriver) StorePointerActions

func (wd *WebDriver) StorePointerActions(inputID string, pointer PointerType, actions ...PointerAction)

func (*WebDriver) SwitchFrame

func (wd *WebDriver) SwitchFrame(frame interface{}) error

func (*WebDriver) SwitchWindow

func (wd *WebDriver) SwitchWindow(name string) error

func (*WebDriver) Text

func (wd *WebDriver) Text() (string, error)

func (*WebDriver) Title

func (wd *WebDriver) Title() (string, error)

func (*WebDriver) Wait

func (wd *WebDriver) Wait(condition Condition) error

func (WebDriver) WaitMinute

func (this WebDriver) WaitMinute(n ...int)

func (WebDriver) WaitSecond

func (this WebDriver) WaitSecond(n ...int)

func (*WebDriver) WaitWithTimeout

func (wd *WebDriver) WaitWithTimeout(condition Condition, timeout time.Duration) error

func (*WebDriver) WaitWithTimeoutAndInterval

func (wd *WebDriver) WaitWithTimeoutAndInterval(condition Condition, timeout, interval time.Duration) error

func (*WebDriver) WindowHandles

func (wd *WebDriver) WindowHandles() ([]string, error)

type WebElement

type WebElement struct {
	// contains filtered or unexported fields
}

func (*WebElement) CSSProperty

func (elem *WebElement) CSSProperty(name string) (string, error)

func (*WebElement) Clear

func (elem *WebElement) Clear() error

func (*WebElement) Click

func (elem *WebElement) Click() error

func (*WebElement) FindElement

func (elem *WebElement) FindElement(by, value string) (*WebElement, error)

func (*WebElement) FindElements

func (elem *WebElement) FindElements(by, value string) ([]*WebElement, error)

func (*WebElement) GetAttribute

func (elem *WebElement) GetAttribute(name string) (string, error)

func (*WebElement) GetProperty

func (elem *WebElement) GetProperty(name string) (string, error)

func (*WebElement) IsDisplayed

func (elem *WebElement) IsDisplayed() (bool, error)

func (*WebElement) IsEnabled

func (elem *WebElement) IsEnabled() (bool, error)

func (*WebElement) IsSelected

func (elem *WebElement) IsSelected() (bool, error)

func (*WebElement) Location

func (elem *WebElement) Location() (*Point, error)

func (*WebElement) LocationInView

func (elem *WebElement) LocationInView() (*Point, error)

func (*WebElement) MarshalJSON

func (elem *WebElement) MarshalJSON() ([]byte, error)

func (*WebElement) MoveTo

func (elem *WebElement) MoveTo(xOffset, yOffset int) error

func (*WebElement) SaveScreenshot

func (elem *WebElement) SaveScreenshot(filename string) error

func (*WebElement) Screenshot

func (elem *WebElement) Screenshot() ([]byte, error)

func (*WebElement) SendKeys

func (elem *WebElement) SendKeys(keys string) error

func (*WebElement) Size

func (elem *WebElement) Size() (*Size, error)

func (*WebElement) Submit

func (elem *WebElement) Submit() error

func (*WebElement) TagName

func (elem *WebElement) TagName() (string, error)

func (*WebElement) Text

func (elem *WebElement) Text() (string, error)

func (WebElement) Wait

func (WebElement) Wait(t time.Duration)

func (WebElement) WaitMinute

func (this WebElement) WaitMinute(n ...int)

func (WebElement) WaitSecond

func (this WebElement) WaitSecond(n ...int)

Directories

Path Synopsis
Package chrome provides Chrome-specific options for WebDriver.
Package chrome provides Chrome-specific options for WebDriver.
Package firefox provides Firefox-specific types for WebDriver.
Package firefox provides Firefox-specific types for WebDriver.
internal
seleniumtest
Package seleniumtest provides tests to exercise package selenium.
Package seleniumtest provides tests to exercise package selenium.
zip
Package zip creates Zip files.
Package zip creates Zip files.
Package log provides logging-related configuration types and constants.
Package log provides logging-related configuration types and constants.
Package sauce interacts with the Sauce Labs hosted browser testing environment.
Package sauce interacts with the Sauce Labs hosted browser testing environment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL