gpt4 book ai didi

selenium - Go - 我如何安装 selenium 以在 go 语言中使用它?

转载 作者:IT王子 更新时间:2023-10-29 01:37:09 30 4
gpt4 key购买 nike

我正在尝试运行和测试此代码,但缺少 Selenium ,我无法将其安装到我的系统中,请问在这种情况下我该怎么办?

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")
}
}

最佳答案

例如,适当设置 GOPATH,

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

引用资料:

Command go

Download and install packages and dependencies

关于selenium - Go - 我如何安装 selenium 以在 go 语言中使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21363476/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com