我尝试去Windows防火墙并打开端口4444,但是这仍然无法正常工作。这是我得到的完整错误:
Failed to open session: Post http://localhost:4444/wd/hub/session: dial tcp [::1]:4444: connectex: No connection could be made because the target machine actively refused it.
最后,这是我正在使用的软件包:“ sourcegraph.com/sourcegraph/go-selenium”。我从来没有在python中遇到这个问题,但是我认为整个应用程序都可以通过防火墙,所以如果我能做到这一点那就太好了。
编辑:我所有的代码(从github示例中窃取)
package main
import (
"sourcegraph.com/sourcegraph/go-selenium"
"fmt"
)
func ExampleFindElement() {
var webDriver selenium.WebDriver
var err error
caps := selenium.Capabilities(map[string]interface{}{"browserName": "firefox"})
if webDriver, err = selenium.NewRemote(caps, "http://localhost:4444/wd/hub"); err != nil {
fmt.Printf("Failed to open session: %s\n", err)
return
}
defer webDriver.Quit()
err = webDriver.Get("https://sourcegraph.com/sourcegraph/go-selenium")
if err != nil {
fmt.Printf("Failed to load page: %s\n", err)
return
}
if title, err := webDriver.Title(); err == nil {
fmt.Printf("Page title: %s\n", title)
} else {
fmt.Printf("Failed to get page title: %s", err)
return
}
var elem selenium.WebElement
elem, err = webDriver.FindElement(selenium.ByCSSSelector, ".repo .name")
if err != nil {
fmt.Printf("Failed to find element: %s\n", err)
return
}
if text, err := elem.Text(); err == nil {
fmt.Printf("Repository: %s\n", text)
} else {
fmt.Printf("Failed to get text of element: %s\n", err)
return
}
// output:
// Page title: go-selenium - Sourcegraph
// Repository: go-selenium
}
func main() {
ExampleFindElement()
}