【问题标题】:Attach an existing web browser to automate using Selenium in C#附加现有的 Web 浏览器以在 C# 中使用 Selenium 自动化
【发布时间】:2017-05-10 03:26:38
【问题描述】:

执行此代码后:

using OpenQA.Selenium.Remote;
...

var driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Firefox());

// To automate...
// driver.Navigate().GoToUrl("http://www.example.com/");

我收到此错误:

OpenQA.Selenium.WebDriverException: '意外错误。 System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:无法建立连接 因为目标机器主动拒绝了 127.0.0.1:4444

  1. 执行该代码会附加现有的 Firefox 浏览器以实现自动化还是什么?
  2. 我该如何解决这个错误?

【问题讨论】:

    标签: c# selenium firefox selenium-webdriver browser


    【解决方案1】:

    您需要让 selenium 服务器运行所有可用的适当 selenium web 驱动程序。

    http://localhost:4444/wd/hub 是由 selenium 服务器组件运行的服务。您将命令发送到 selenium 服务器,然后它使用适当的 webdriver 执行它们。

    在这里阅读:http://www.seleniumhq.org/docs/03_webdriver.jsp#webdriver-and-the-selenium-server

    【讨论】:

    • 那么下载selenium-server-standalone-3.4.0.jar有必要吗?
    • 是的。您需要下载并运行该 jar。您还需要适合您的浏览器的网络驱动程序(在同一下载页面上)
    • 您的意思是,在 Python 中使用 127.0.0.1:60622/hub 执行此操作 stackoverflow.com/a/32882207/4883372 还需要 selenium-server-standalone-3.4.0.jar 吗?跨度>
    • 没有。您需要做的就是安装 java,然后在 .bat 文件中输入 java -jar selenium-server-standalone-3.4.0.jar 并将其保存在同一目录中并运行它。还将WebDriver放在同一目录中您不需要python。您遇到的错误是因为该 .jar 文件上的程序未运行,因此无法连接“无法建立连接...”
    • @5ervant 我之前在我的wiki上写过一篇关于这个的文章https://github.com/NattyMan0007/NUnitDocs/wiki/Selenium-Server-Configuration
    猜你喜欢
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    相关资源
    最近更新 更多