go的selenium库 github.com/tebeka/selenium 官方文档

go的selenium库 github.com/tebeka/selenium 官方文档地址
https://pkg.go.dev/github.com/tebeka/selenium#HTMLUnit

源码的github地址
https://github.com/tebeka/selenium

翻译后的文档
Constants
Variables
func DeleteSession(urlPrefix, id string) error
func SetDebug(debug bool)
type Capabilities
func (c Capabilities) AddChrome(f chrome.Capabilities)
func (c Capabilities) AddFirefox(f firefox.Capabilities)
func (c Capabilities) AddLogging(l log.Capabilities)
func (c Capabilities) AddProxy(p Proxy)
func (c Capabilities) SetLogLevel(typ log.Type, level log.Level)
type Condition
type Cookie
type Error
func (e *Error) Error() string
type FrameBuffer
func NewFrameBuffer() (*FrameBuffer, error)
func NewFrameBufferWithOptions(options FrameBufferOptions) (*FrameBuffer, error)
func (f FrameBuffer) Stop() error
type FrameBufferOptions
type Point
type Proxy
type ProxyType
type Service
func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error)
func NewGeckoDriverService(path string, port int, opts ...ServiceOption) (*Service, error)
func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error)
func (s Service) FrameBuffer() *FrameBuffer
func (s *Service) Stop() error
type ServiceOption
func ChromeDriver(path string) ServiceOption
func Display(d, xauthPath string) ServiceOption
func GeckoDriver(path string) ServiceOption
func HTMLUnit(path string) ServiceOption
func JavaPath(path string) ServiceOption
func Output(w io.Writer) ServiceOption
func StartFrameBuffer() ServiceOption
func StartFrameBufferWithOptions(options FrameBufferOptions) ServiceOption
type Size
type Status
type WebDriver
func NewRemote(capabilities Capabilities, urlPrefix string) (WebDriver, error)
type WebElement


Package
View Source
const (
//DefaultWaitInterval是的默认轮询间隔硒。等等
//功能。
DefaultWaitInterval = 100 * time.Millisecond

//DefaultWaitTimeout是的默认超时硒。等等功能。
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"
)
//查找元素的方法。

View Source
const (
LeftButton = iota
MiddleButton
RightButton
)
Mouse buttons.

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')
)
//特殊键盘键,用于发送键。

View Source
const (
//直接连接-未使用代理。
Direct ProxyType = "direct"
//手动配置代理设置,例如为HTTP设置代理
//用于FTP等。
Manual = "manual"
//自动检测代理,可能使用WPAD
Autodetect = "autodetect"
//使用的系统设置。
System = "system"
//PAC-从URL自动配置代理。
PAC = "pac"
)
View Source
const DefaultURLPrefix = "http:const DefaultURLPrefix=“http://127.0.0.1:4444/wd/轮毂“
//DefaultURLPrefix是提供WebDriver API的默认HTTP端点。

View Source
var HTTPClient = http.DefaultClient
//HTTPClient是用于与WebDriver服务器通信的默认客户端。

func DeleteSession(urlPrefix, id string) error
//DeleteSession删除由urlPrefix和会话ID指定的WebDriver实例上的现有会话。

func SetDebug(debug bool)
//设置调试模式

type Capabilities map[string]interface{}
//功能使用标准和特定于浏览器的选项配置WebDriver进程和目标浏览器。

func (c Capabilities) AddChrome(f chrome.Capabilities)
//AddChrome增加了特定于Chrome的功能。

func (c Capabilities) AddFirefox(f firefox.Capabilities)
//AddFirefox添加了特定于Firefox的功能。

func (c Capabilities) AddLogging(l log.Capabilities)
//AddLogging将日志配置添加到功能中。

func (c Capabilities) AddProxy(p Proxy)
//AddProxy将代理配置添加到功能中。

func (c Capabilities) SetLogLevel(typ log.Type, level log.Level)
//SetLogLevel设置组件的日志级别。这是传递信息的捷径日志功能实例添加日志记录。

type Condition func(wd WebDriver) (bool, error)
//条件是作为参数传递的类型的别名硒。等等(条件条件)(错误)功能。

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"`
}
//Cookie表示HTTP Cookie。

type Error struct {
//Err包含服务器提供的常规错误字符串。
Err string `json:"error"`
//消息是特定于故障的详细的、人类可读的消息。
Message string `json:"message"`
//Stacktrace可能包含发生错误的服务器端Stacktrace。
Stacktrace string `json:"stacktrace"`
//HTTPCode是服务器返回的HTTP状态代码。
HTTPCode int
//LegacyCode是在遗留Selenium中定义的“响应状态代码”
//WebDriver JSON wire协议。此代码仅由旧版本生成
//Selenium WebDriver版本、Chromedriver和InternetExplorerDriver。
LegacyCode int
}
//错误包含有关命令失败的信息。请参见https://www.w3.org/TR/webdriver/#处理-错误。

//此错误类型仅由实现W3C规范的服务器返回。

func (e *Error) Error() string
//Error实现错误接口。

type FrameBuffer struct {
//Display是Xvfb进程承载的X11显示号
//(前面没有冒号)。
Display string
//AuthPath是允许X客户端的X11授权文件的路径
//使用X服务器。这通常通过
//XAUTHORITY环境变量。
AuthPath string
//包含已筛选或未报告的字段
}
//帧缓冲区控制作为后台进程运行的X虚拟帧缓冲区。

func NewFrameBuffer() (*FrameBuffer, error)
//NewFrameBuffer启动在后台运行的X虚拟帧缓冲区。

//这相当于使用空的NewFrameBufferWithOptions调用NewFrameBufferWithOptions。

func NewFrameBufferWithOptions(options FrameBufferOptions) (*FrameBuffer, error)
//NewFrameBufferWithOptions启动在后台运行的X虚拟帧缓冲区。可以填充FrameBufferOptions来更改帧缓冲区的行为。

func (f FrameBuffer) Stop() error
//Stop终止后台帧缓冲进程并删除X授权文件。

type FrameBufferOptions struct {
//ScreenSize是帧缓冲区屏幕大小的选项。
//其形式为“{width}x{height}[x{depth}]”。例如:“1024x768x24”
ScreenSize string
}
//FrameBufferOptions描述可用于创建帧缓冲区的选项。

type Point struct {
X, Y int
}
//点是二维点。

type Proxy struct {
//类型是要使用的代理的类型。这需要填充。
Type ProxyType `json:"proxyType"`

//AutoConfigure是用于代理自动配置的URL。这是
//如果类型设置为PAC,则为必需。
AutoconfigURL string `json:"proxyAutoconfigUrl,omitempty"`

//当“类型”设置为“手动”时,将使用以下选项。
//注意,在Firefox中,到localhost的连接在默认情况下不被代理,
//即使设置了代理。这可以通过首选项设置来覆盖。
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"`

//W3C规范草案也包括端口字段。根据
//规范中,端口也可以包含在上述地址中。然而,
//在Geckodriver实现中,端口必须由
//其他字段。
HTTPPort  int `json:"httpProxyPort,omitempty"`
SSLPort   int `json:"sslProxyPort,omitempty"`
SocksPort int `json:"socksProxyPort,omitempty"`
}
//代理指定浏览器中代理的配置。将Capabilities中的键“proxy”设置为此类型的实例。

type ProxyType string
//ProxyType是可用代理类型的枚举。

type Service struct {
//包含已筛选或未报告的字段
}
//服务控制本地运行的Selenium子进程。

func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error)
//NewChromeDriverService在后台启动ChromeDriver实例。

func NewGeckoDriverService(path string, port int, opts ...ServiceOption) (*Service, error)
//NewGeckoDriverService在后台启动一个GeckoDriver实例。

func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error)
//NewSeleniumService在后台启动一个Selenium实例。

func (s Service) FrameBuffer() *FrameBuffer
//如果服务启动了帧缓冲区,则返回帧缓冲区;否则返回nil。

func (s *Service) Stop() error
//Stop关闭WebDriver服务,并关闭X虚拟帧缓冲区(如果已启动)。

type ServiceOption func(*Service) error
//ServiceOption配置服务实例。

func ChromeDriver(path string) ServiceOption
//ChromeDriver为Selenium服务器设置ChromeDriver的路径。此服务选项仅在调用NewSeleniumService时有用。

func Display(d, xauthPath string) ServiceOption
//Display指定将Display环境变量设置为的值,以及包含写入该X服务器所需凭据的Xauthority文件的路径。

func GeckoDriver(path string) ServiceOption
//GeckoDriver为Selenium服务器设置GeckoDriver二进制文件的路径。与其他驱动程序不同,Selenium服务器不支持在运行时指定geckodriver路径。此服务选项仅在调用NewSeleniumService时有用。

func HTMLUnit(path string) ServiceOption
//HTMLUnit为HTMLUnit驱动程序指定JAR的路径(用依赖项编译)。

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

func JavaPath(path string) ServiceOption
//JavaPath指定JRE的路径。

func Output(w io.Writer) ServiceOption
//Output指定WebDriver服务应该登录到提供的writer。

func StartFrameBuffer() ServiceOption
//StartFrameBuffer导致X虚拟帧缓冲区在WebDriver服务之前启动。当服务本身停止时,帧缓冲进程将终止。

//这相当于使用空映射调用StartFrameBufferWithOptions。

func StartFrameBufferWithOptions(options FrameBufferOptions) ServiceOption
//StartFrameBufferWithOptions导致X虚拟帧缓冲区在WebDriver服务之前启动。当服务本身停止时,帧缓冲进程将终止。

type Size struct {
Width, Height int
}
//Size是HTML元素的大小。

type Status struct {
//以下字段由Selenium和ChromeDriver使用。
Java struct {
Version string
}
Build struct {
Version, Revision, Time string
}
OS struct {
Arch, Name, Version string
}

//以下字段由w3cwebdriver规范和
//是壁虎河使用的。
Ready   bool
Message string
}
//Status包含Status方法返回的信息。

type WebDriver interface {
//Status返回有关服务器环境的各种信息。
Status() (*Status, error)

//NewSession启动新会话并返回会话ID。
NewSession() (string, error)

//SessionId返回当前会话ID
//已弃用:此标识符的格式不正确。使用SessionID
//相反。
SessionId() string

//SessionID返回当前会话ID。
SessionID() string

//SwitchSession切换到给定的会话ID。
SwitchSession(sessionID string) error

//Capabilities返回当前会话的功能。
Capabilities() (Capabilities, error)

//SetAsyncScriptTimeout设置异步脚本运行的时间量
//允许在中止之前运行。超时时间将四舍五入
//精确到毫秒。
SetAsyncScriptTimeout(timeout time.Duration) error
//SetImplicitWaitTimeout设置驱动程序在
//搜索元素。超时将四舍五入到最接近的毫秒。
SetImplicitWaitTimeout(timeout time.Duration) error
//SetPageLoadTimeout设置驱动程序在
//加载页面。超时将四舍五入到最接近的毫秒。
SetPageLoadTimeout(timeout time.Duration) error

//退出结束当前会话。浏览器实例将关闭。
Quit() error

//CurrentWindowHandle返回当前窗口句柄的ID。
CurrentWindowHandle() (string, error)
//WindowHandles返回当前打开窗口的ID。
WindowHandles() ([]string, error)
//CurrentURL返回浏览器的当前URL。
CurrentURL() (string, error)
//Title返回当前页的标题。
Title() (string, error)
//PageSource返回当前页的源。
PageSource() (string, error)
//关闭关闭当前窗口。
Close() error
//SwitchFrame切换到给定的帧。frame参数可以是
//frame的ID作为字符串,其WebElement实例作为
//GetElement或nil切换到当前顶级浏览上下文。
SwitchFrame(frame interface{}) error
//SwitchWindow将上下文切换到指定的窗口。
SwitchWindow(name string) error
//CloseWindow关闭指定的窗口。
CloseWindow(name string) error
//最大化窗口最大化窗口。如果名称为空,则当前
//窗口将最大化。
MaximizeWindow(name string) error
//调整窗口大小更改窗口的尺寸。如果名称为空,则
//当前窗口将最大化。
ResizeWindow(name string, width, height int) error

//Get将浏览器导航到提供的URL。
Get(url string) error
//历史前进。
Forward() error
//历史倒退。
Back() error
//刷新刷新页面。
Refresh() error

//FindElement只在当前页面的DOM中找到一个元素。
FindElement(by, value string) (WebElement, error)
//FindElement可以在当前页面的DOM中找到许多元素。
FindElements(by, value string) ([]WebElement, error)
//ActiveElement返回页面上当前活动的元素。
ActiveElement() (WebElement, error)

//decodelement对单个元素响应进行解码。
DecodeElement([]byte) (WebElement, error)
//解码元素解码多元素响应。
DecodeElements([]byte) ([]WebElement, error)

//GetCookies返回浏览器jar中的所有cookies。
GetCookies() ([]Cookie, error)
//GetCookie返回jar中的指定cookie(如果存在)。这种方法是可行的
//仅针对Firefox实现。
GetCookie(name string) (Cookie, error)
//AddCookie将cookie添加到浏览器的jar中。
AddCookie(cookie *Cookie) error
//DeleteAllCookies删除浏览器jar中的所有cookies。
DeleteAllCookies() error
//DeleteCookie删除浏览器jar中的cookie。
DeleteCookie(name string) error

//单击鼠标按钮。按钮应该是RightButton之一,
//中键或左键。
Click(button int) error
//双击鼠标左键两次。
DoubleClick() error
//ButtonDown使鼠标左键被按下。
ButtonDown() error
//ButtonUp使鼠标左键被释放。
ButtonUp() error

//SendModifier将修改键发送到活动元素。修饰语
//可以是ShiftKey、ControlKey、AltKey、MetaKey之一。
//不推荐使用:改用KeyDown或KeyUp。
SendModifier(modifier string, isDown bool) error
//KeyDown向活动元素发送一系列击键。此方法
//与SendKeys类似,但没有隐式终止。修饰符是
//未在每次通话结束时释放。
KeyDown(keys string) error
//KeyUp表示KeyDown发送的上一次击键应该是释放。
KeyUp(keys string) error

//截图截取浏览器窗口的截图。
Screenshot() ([]byte, error)

//日志获取日志。日志类型必须事先在中配置能力。
//注意:将在IE11或边缘驱动程序上返回错误(未实现)。
Log(typ log.Type) ([]log.Message, error)

//解除警报解除当前警报。
DismissAlert() error

//AcceptAlert接受当前警报。
AcceptAlert() error

//AlertText返回当前警报文本。
AlertText() (string, error)

//SetAlertText设置当前警报文本。
SetAlertText(text string) error

//ExecuteScript执行脚本。
ExecuteScript(script string, args []interface{}) (interface{}, error)

//ExecuteScriptAsync异步执行脚本。
ExecuteScriptAsync(script string, args []interface{}) (interface{}, error)

//ExecuteScriptRaw执行脚本,但不执行JSON解码。
ExecuteScriptRaw(script string, args []interface{}) ([]byte, error)

//ExecuteScriptAsyncRaw异步执行脚本,但不执行
//执行JSON解码。
ExecuteScriptAsyncRaw(script string, args []interface{}) ([]byte, error)

//WaitWithTimeoutAndInterval等待条件的计算结果为true。
WaitWithTimeoutAndInterval(condition Condition, timeout, interval time.Duration) error

//WaitWithTimeout的工作方式类似于WaitWithTimeoutAndInterval,但使用默认的轮询间隔。
WaitWithTimeout(condition Condition, timeout time.Duration) error

//Wait的工作方式类似于WaitWithTimeoutAndInterval,但使用默认的超时和轮询间隔。
Wait(condition Condition) error
}
//WebDriver定义WebDriver支持的方法。

func NewRemote(capabilities Capabilities, urlPrefix string) (WebDriver, error)
//NewRemote创建新的远程客户端,这也将启动一个新会话。能力提供所需的能力。urlPrefix是Selenium服务器的URL,必须以协议(http、https等)作为前缀。

//为urlPrefix提供空字符串会导致使用DefaultURLPrefix。

type WebElement interface {
//单击元素。
Click() error

//SendKeys类型到元素中。
SendKeys(keys string) error

//提交按钮。
Submit() error

//清除清除元素。
Clear() error

//MoveTo将鼠标从元素中心移动到相对坐标,如果
//元素不可见,将滚动到视图中。
MoveTo(xOffset, yOffset int) error

//FindElement查找子元素。
FindElement(by, value string) (WebElement, error)

//FindElement查找多个子元素。
FindElements(by, value string) ([]WebElement, error)

//标记名返回元素的名称。
TagName() (string, error)

//Text返回元素的文本。
Text() (string, error)

//如果选择了元素,IsSelected将返回true。
IsSelected() (bool, error)

//如果元素已启用,IsEnabled将返回true。
IsEnabled() (bool, error)

//如果显示元素,IsDisplayed将返回true。
IsDisplayed() (bool, error)

//GetAttribute返回元素的命名属性。
GetAttribute(name string) (string, error)

//Location返回元素的位置。
Location() (*Point, error)

//LocationInView返回元素在滚动后的位置
//进入视野。
LocationInView() (*Point, error)

//Size返回元素的大小。
Size() (*Size, error)

//CSSProperty返回
//元素。
CSSProperty(name string) (string, error)

//截图采取的属性滚动截图,如果必要的。
Screenshot(scroll bool) ([]byte, error)
}


源文档
Constants
Variables
func DeleteSession(urlPrefix, id string) error
func SetDebug(debug bool)
type Capabilities
func (c Capabilities) AddChrome(f chrome.Capabilities)
func (c Capabilities) AddFirefox(f firefox.Capabilities)
func (c Capabilities) AddLogging(l log.Capabilities)
func (c Capabilities) AddProxy(p Proxy)
func (c Capabilities) SetLogLevel(typ log.Type, level log.Level)
type Condition
type Cookie
type Error
func (e *Error) Error() string
type FrameBuffer
func NewFrameBuffer() (*FrameBuffer, error)
func NewFrameBufferWithOptions(options FrameBufferOptions) (*FrameBuffer, error)
func (f FrameBuffer) Stop() error
type FrameBufferOptions
type Point
type Proxy
type ProxyType
type Service
func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error)
func NewGeckoDriverService(path string, port int, opts ...ServiceOption) (*Service, error)
func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error)
func (s Service) FrameBuffer() *FrameBuffer
func (s *Service) Stop() error
type ServiceOption
func ChromeDriver(path string) ServiceOption
func Display(d, xauthPath string) ServiceOption
func GeckoDriver(path string) ServiceOption
func HTMLUnit(path string) ServiceOption
func JavaPath(path string) ServiceOption
func Output(w io.Writer) ServiceOption
func StartFrameBuffer() ServiceOption
func StartFrameBufferWithOptions(options FrameBufferOptions) ServiceOption
type Size
type Status
type WebDriver
func NewRemote(capabilities Capabilities, urlPrefix string) (WebDriver, error)
type WebElement

Package
View Source
const (
// 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 (
LeftButton = iota
MiddleButton
RightButton
)
Mouse buttons.

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 DefaultURLPrefix = "http://127.0.0.1:4444/wd/hub"
DefaultURLPrefix is the default HTTP endpoint that offers the WebDriver API.

View Source
var HTTPClient = http.DefaultClient
HTTPClient is the default client to use to communicate with the WebDriver server.

func DeleteSession(urlPrefix, id string) error
DeleteSession deletes an existing session at the WebDriver instance specified by the urlPrefix and the session ID.

func SetDebug(debug bool)
SetDebug sets debug mode

type Capabilities map[string]interface{}
Capabilities configures both the WebDriver process and the target browsers, with standard and browser-specific options.

func (c Capabilities) AddChrome(f chrome.Capabilities)
AddChrome adds Chrome-specific capabilities.

func (c Capabilities) AddFirefox(f firefox.Capabilities)
AddFirefox adds Firefox-specific capabilities.

func (c Capabilities) AddLogging(l log.Capabilities)
AddLogging adds logging configuration to the capabilities.

func (c Capabilities) AddProxy(p Proxy)
AddProxy adds proxy configuration to the capabilities.

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 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"`
}
Cookie represents an HTTP cookie.

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 (e *Error) Error() string
Error implements the error interface.

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() (*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(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 (f FrameBuffer) Stop() error
Stop kills the background frame buffer process and removes the X authorization file.

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 Point struct {
X, Y int
}
Point is a 2D point.

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 string
ProxyType is an enumeration of the types of proxies available.

type Service struct {
// contains filtered or unexported fields
}
Service controls a locally-running Selenium subprocess.

func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error)
NewChromeDriverService starts a ChromeDriver instance in the background.

func NewGeckoDriverService(path string, port int, opts ...ServiceOption) (*Service, error)
NewGeckoDriverService starts a GeckoDriver instance in the background.

func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error)
NewSeleniumService starts a Selenium instance in the background.

func (s Service) FrameBuffer() *FrameBuffer
FrameBuffer returns the FrameBuffer if one was started by the service and nil otherwise.

func (s *Service) Stop() error
Stop shuts down the WebDriver service, and the X virtual frame buffer if one was started.

type ServiceOption func(*Service) error
ServiceOption configures a Service instance.

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(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(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(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(path string) ServiceOption
JavaPath specifies the path to the JRE.

func Output(w io.Writer) ServiceOption
Output specifies that the WebDriver service should log to the provided writer.

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(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 struct {
Width, Height int
}
Size is a size of HTML element.

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 interface {
// Status returns various pieces of information about the server environment.
Status() (*Status, error)

// NewSession starts a new session and returns the session ID.
NewSession() (string, error)

// SessionId returns the current session ID
//
// Deprecated: This identifier is not Go-style correct. Use SessionID
// instead.
SessionId() string

// SessionID returns the current session ID.
SessionID() string

// SwitchSession switches to the given session ID.
SwitchSession(sessionID string) error

// Capabilities returns the current session's capabilities.
Capabilities() (Capabilities, error)

// SetAsyncScriptTimeout sets the amount of time that asynchronous scripts
// are permitted to run before they are aborted. The timeout will be rounded
// to nearest millisecond.
SetAsyncScriptTimeout(timeout time.Duration) error
// SetImplicitWaitTimeout sets the amount of time the driver should wait when
// searching for elements. The timeout will be rounded to nearest millisecond.
SetImplicitWaitTimeout(timeout time.Duration) error
// SetPageLoadTimeout sets the amount of time the driver should wait when
// loading a page. The timeout will be rounded to nearest millisecond.
SetPageLoadTimeout(timeout time.Duration) error

// Quit ends the current session. The browser instance will be closed.
Quit() error

// CurrentWindowHandle returns the ID of current window handle.
CurrentWindowHandle() (string, error)
// WindowHandles returns the IDs of current open windows.
WindowHandles() ([]string, error)
// CurrentURL returns the browser's current URL.
CurrentURL() (string, error)
// Title returns the current page's title.
Title() (string, error)
// PageSource returns the current page's source.
PageSource() (string, error)
// Close closes the current window.
Close() error
// SwitchFrame switches to the given frame. The frame parameter can be the
// frame's ID as a string, its WebElement instance as returned by
// GetElement, or nil to switch to the current top-level browsing context.
SwitchFrame(frame interface{}) error
// SwitchWindow switches the context to the specified window.
SwitchWindow(name string) error
// CloseWindow closes the specified window.
CloseWindow(name string) error
// MaximizeWindow maximizes a window. If the name is empty, the current
// window will be maximized.
MaximizeWindow(name string) error
// ResizeWindow changes the dimensions of a window. If the name is empty, the
// current window will be maximized.
ResizeWindow(name string, width, height int) error

// Get navigates the browser to the provided URL.
Get(url string) error
// Forward moves forward in history.
Forward() error
// Back moves backward in history.
Back() error
// Refresh refreshes the page.
Refresh() error

// FindElement finds exactly one element in the current page's DOM.
FindElement(by, value string) (WebElement, error)
// FindElement finds potentially many elements in the current page's DOM.
FindElements(by, value string) ([]WebElement, error)
// ActiveElement returns the currently active element on the page.
ActiveElement() (WebElement, error)

// DecodeElement decodes a single element response.
DecodeElement([]byte) (WebElement, error)
// DecodeElements decodes a multi-element response.
DecodeElements([]byte) ([]WebElement, error)

// GetCookies returns all of the cookies in the browser's jar.
GetCookies() ([]Cookie, error)
// GetCookie returns the named cookie in the jar, if present. This method is
// only implemented for Firefox.
GetCookie(name string) (Cookie, error)
// AddCookie adds a cookie to the browser's jar.
AddCookie(cookie *Cookie) error
// DeleteAllCookies deletes all of the cookies in the browser's jar.
DeleteAllCookies() error
// DeleteCookie deletes a cookie to the browser's jar.
DeleteCookie(name string) error

// Click clicks a mouse button. The button should be one of RightButton,
// MiddleButton or LeftButton.
Click(button int) error
// DoubleClick clicks the left mouse button twice.
DoubleClick() error
// ButtonDown causes the left mouse button to be held down.
ButtonDown() error
// ButtonUp causes the left mouse button to be released.
ButtonUp() error

// SendModifier sends the modifier key to the active element. The modifier
// can be one of ShiftKey, ControlKey, AltKey, MetaKey.
//
// Deprecated: Use KeyDown or KeyUp instead.
SendModifier(modifier string, isDown bool) error
// KeyDown sends a sequence of keystrokes to the active element. This method
// is similar to SendKeys but without the implicit termination. Modifiers are
// not released at the end of each call.
KeyDown(keys string) error
// KeyUp indicates that a previous keystroke sent by KeyDown should be
// released.
KeyUp(keys string) error
// Screenshot takes a screenshot of the browser window.
Screenshot() ([]byte, error)
// Log fetches the logs. Log types must be previously configured in the
// capabilities.
//
// NOTE: will return an error (not implemented) on IE11 or Edge drivers.
Log(typ log.Type) ([]log.Message, error)

// DismissAlert dismisses current alert.
DismissAlert() error
// AcceptAlert accepts the current alert.
AcceptAlert() error
// AlertText returns the current alert text.
AlertText() (string, error)
// SetAlertText sets the current alert text.
SetAlertText(text string) error

// ExecuteScript executes a script.
ExecuteScript(script string, args []interface{}) (interface{}, error)
// ExecuteScriptAsync asynchronously executes a script.
ExecuteScriptAsync(script string, args []interface{}) (interface{}, error)

// ExecuteScriptRaw executes a script but does not perform JSON decoding.
ExecuteScriptRaw(script string, args []interface{}) ([]byte, error)
// ExecuteScriptAsyncRaw asynchronously executes a script but does not
// perform JSON decoding.
ExecuteScriptAsyncRaw(script string, args []interface{}) ([]byte, error)

// WaitWithTimeoutAndInterval waits for the condition to evaluate to true.
WaitWithTimeoutAndInterval(condition Condition, timeout, interval time.Duration) error

// WaitWithTimeout works like WaitWithTimeoutAndInterval, but with default polling interval.
WaitWithTimeout(condition Condition, timeout time.Duration) error

//Wait works like WaitWithTimeoutAndInterval, but using the default timeout and polling interval.
Wait(condition Condition) error
}
WebDriver defines methods supported by WebDriver drivers.

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.

type WebElement interface {
// Click clicks on the element.
Click() error
// SendKeys types into the element.
SendKeys(keys string) error
// Submit submits the button.
Submit() error
// Clear clears the element.
Clear() error
// MoveTo moves the mouse to relative coordinates from center of element, If
// the element is not visible, it will be scrolled into view.
MoveTo(xOffset, yOffset int) error

// FindElement finds a child element.
FindElement(by, value string) (WebElement, error)
// FindElement finds multiple children elements.
FindElements(by, value string) ([]WebElement, error)

// TagName returns the element's name.
TagName() (string, error)
// Text returns the text of the element.
Text() (string, error)
// IsSelected returns true if element is selected.
IsSelected() (bool, error)
// IsEnabled returns true if the element is enabled.
IsEnabled() (bool, error)
// IsDisplayed returns true if the element is displayed.
IsDisplayed() (bool, error)
// GetAttribute returns the named attribute of the element.
GetAttribute(name string) (string, error)
// Location returns the element's location.
Location() (*Point, error)
// LocationInView returns the element's location once it has been scrolled
// into view.
LocationInView() (*Point, error)
// Size returns the element's size.
Size() (*Size, error)
// CSSProperty returns the value of the specified CSS property of the
// element.
CSSProperty(name string) (string, error)
// Screenshot takes a screenshot of the attribute scroll'ing if necessary.
Screenshot(scroll bool) ([]byte, error)
}

猜你喜欢

转载自blog.csdn.net/liao__ran/article/details/113887243