druybew06513 2018-08-15 06:35
浏览 333

Go-selenium:无法连接,因为目标计算机主动拒绝了它

I tried going to windows firewall and opening port 4444, however this still does not work. This is the complete error I'm getting:

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.

And lastly this is the package I'm using: "sourcegraph.com/sourcegraph/go-selenium". I never ran into this problem in python but I assume the whole application was allowed through the firewall, so if I could do that for go that would be great.

Edit: All my code (stolen from the github example)

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
", err)
        return
    }
    defer webDriver.Quit()

err = webDriver.Get("https://sourcegraph.com/sourcegraph/go-selenium")
if err != nil {
    fmt.Printf("Failed to load page: %s
", err)
    return
}

if title, err := webDriver.Title(); err == nil {
    fmt.Printf("Page title: %s
", 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
", err)
    return
}

if text, err := elem.Text(); err == nil {
    fmt.Printf("Repository: %s
", text)
} else {
    fmt.Printf("Failed to get text of element: %s
", err)
    return
}

// output:
// Page title: go-selenium - Sourcegraph
// Repository: go-selenium
}

func main() {
    ExampleFindElement()
}
  • 写回答

1条回答 默认 最新

  • Yx2020 2021-03-12 22:03
    关注

    没解决 咋办啊 我也遇到了 

    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料