首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Go语言中安装selenium来使用它?

如何在Go语言中安装selenium来使用它?
EN

Stack Overflow用户
提问于 2014-01-26 12:43:15
回答 1查看 3.1K关注 0票数 2

我正在试着运行和测试这段代码,但是selenium丢失了,我无法在我的系统中安装它,在这种情况下我应该怎么办?

代码语言:javascript
复制
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")
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-26 13:00:23

例如,在适当设置GOPATH之后,

代码语言:javascript
复制
$ env | grep '^GOPATH'
GOPATH=/home/peter/gopath
$ go get -v bitbucket.org/tebeka/selenium
bitbucket.org/tebeka/selenium (download)
bitbucket.org/tebeka/selenium
$ 

参考文献:

命令启动

下载和安装软件包和依赖项

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21363476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档