Go – how can i install selenium to use it in go language?

huangapple go评论97阅读模式
英文:

Go - how can i install selenium to use it in go language?

问题

我正在尝试运行和测试这段代码,但是缺少selenium,并且我无法在我的系统中安装它,在这种情况下我应该怎么办?

错误信息:
test.go:8:2: import "bitbucket.org/tebeka/selenium": 找不到包

我尝试安装的包:

apt-get install goisntall

读取软件包列表... 完成
正在构建依赖关系树
读取状态信息... 完成
E: 无法定位软件包 goisntall

apt-cache search goinstall

golang-src - Go编程语言编译器-源文件

测试代码:
/* Selenium示例 goinstall bitbucket.org/tebeka/selenium */
package yahoo

import (
"strings"
"testing"
"bitbucket.org/tebeka/selenium"
)

func TestYahoo(t testing.T) {
/
我们想要使用Firefox,不太关心版本 */
caps := selenium.Capabilities {
"browserName": "firefox",
}
wd, _ := selenium.NewRemote(caps, "", "")
defer wd.Quit()

/* 导航到Yahoo */
wd.Get("http://www.yahoo.com")

/* 填写搜索框 */
input, err := wd.FindElement(selenium.ByName, "p")
if err != nil {
    t.Error(err.String())
}
err = input.SendKeys("golang")
if err != nil {
    t.Error(err.String())
}

/* 点击搜索按钮 */
button, err := wd.FindElement(selenium.ById, "search-submit")
if err != nil {
    t.Error(err.String())
}
err = button.Click()
if err != nil {
    t.Error(err.String())
}

/* 检查是否得到了预期的结果 */
source, err := wd.PageSource()
if err != nil {
    t.Error(err.String())
}

if !strings.Contains(source, "The Go Programming Language") {
    t.Error("Google找不到Go")
}

}

英文:

I am trying to run and test this code but the selenium is missing and i cant install it in my system, what should i do in that case please?

ERROR: while execute
test.go:8:2: import "bitbucket.org/tebeka/selenium": cannot find package

INSTALL the package i tried:
# apt-get install goisntall
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package goisntall
# apt-cache search goinstall
golang-src - Go programming language compiler - source files

CODE: testing
/* Selenium example goinstall bitbucket.org/tebeka/selenium */
package yahoo

import (
  "strings"
  "testing"
  "bitbucket.org/tebeka/selenium"
)

func TestYahoo(t *testing.T) {
	/* We want firefox, don't care about version much */
	caps := selenium.Capabilities {
		"browserName": "firefox",
	}
	wd, _ := selenium.NewRemote(caps, "", "")
	defer wd.Quit()

	/* Navigate to Yahoo */
	wd.Get("http://www.yahoo.com")

	/* Fill the search box */
	input, err := wd.FindElement(selenium.ByName, "p")
	if err != nil {
		t.Error(err.String())
	}
	err = input.SendKeys("golang")
	if err != nil {
		t.Error(err.String())
	}

	/* Hit the search button */
	button, err := wd.FindElement(selenium.ById, "search-submit")
	if err != nil {
		t.Error(err.String())
	}
	err = button.Click()
	if err != nil {
		t.Error(err.String())
	}

	/* See that we get expected result */
	source, err := wd.PageSource()
	if err != nil {
		t.Error(err.String())
	}

	if !strings.Contains(source, "The Go Programming Language") {
		t.Error("Google can't find Go")
	}
}

答案1

得分: 3

例如,如果适当设置了GOPATH,

$ env | grep '^GOPATH'
GOPATH=/home/peter/gopath
$ go get -v bitbucket.org/tebeka/selenium
bitbucket.org/tebeka/selenium (下载)
bitbucket.org/tebeka/selenium
$ 

参考资料:

Command go

下载和安装包及其依赖项

英文:

For example, with GOPATH set appropriately,

$ env | grep '^GOPATH'
GOPATH=/home/peter/gopath
$ go get -v bitbucket.org/tebeka/selenium
bitbucket.org/tebeka/selenium (download)
bitbucket.org/tebeka/selenium
$ 

References:

Command go

Download and install packages and dependencies

huangapple
  • 本文由 发表于 2014年1月26日 20:43:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/21363476.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定