selenium - Go-selenium:无法建立连接,因为目标机器主动拒绝它
问题描述
我尝试去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()
}
解决方案
推荐阅读
- python - 停止 Numpy 将数组中的小数字舍入为零
- azure-pipelines - azure 数据工厂管道运行历史记录到 excel
- typescript - 如何在 TypeScript 中强制两种类型不兼容?
- java - 我希望镶木地板文件数据为以下字符串格式。有人可以帮我吗?
- python - 如何在Python中迭代函数的输出
- rest - 在模拟响应中验证传递的参数值。REST 请求 | Groovy 语言
- javascript - 如何在 Google Closure Compiler 中指定 ES6 导入的路径?
- java - 使用 loadmore 过滤 RecyclerView
- python - 如何使用芹菜中的字典列表进行分组
- amazon-web-services - 允许某些以 x 开头的用户代理进入文件夹