【问题标题】:Selenium on Raspberry Pi using Mono (C#)使用 Mono (C#) 在 Raspberry Pi 上使用 Selenium
【发布时间】:2017-12-10 06:47:52
【问题描述】:

我使用 selenium 编写了一个 C# 程序。在 Windows 上使用它时效果很好,但在 Rapsberry Pi 上却不行。 [它可以在没有硒部分的情况下工作]。

代码如下:

var options = new FirefoxOptions();
                options.BrowserExecutableLocation = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";

//IWebDriver driver = new FirefoxDriver(options);   // WINDOWS VERSION
IWebDriver driver = new FirefoxDriver(); // LINUX VERSION
string xpath = "html/body/div[1]/div/main/div/section/section[2]/div/div[2]/div[1]/div/div/textarea";
string xpathButton = "html/body/div[1]/div/main/div/section/section[2]/div/div[2]/div[1]/div/button";

driver.Url = myurl;
driver.FindElement(By.XPath(xpathButton)).Click();
List<IWebElement> webElems = driver.FindElements(By.XPath(xpath)).ToList();

string comparestring = "";
int comparecounter = 0;

foreach (IWebElement element in webElems)
{
    comparestring = element.Text;
}

我在树莓派上不断收到以下错误:

连接被拒绝

和: OpenQA.Selenium.WebDriverException:无法找到一组匹配的功能 在 OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError (OpenQA.Selenium.Remote.Response errorResponse) [0x00000] in :0 在 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(System.String driverCommandToExecute,System.Collections.Generic.Dictionary`2 参数)[0x00000] 中:0 在 OpenQA.Selenium.Remote.RemoteWebDriver.StartSession (ICapabilities desiredCapabilities) [0x00000] in :0 在 OpenQA.Selenium.Remote.RemoteWebDriver..ctor (ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) [0x00000] in :0 在 OpenQA.Selenium.Firefox.FirefoxDriver..ctor (OpenQA.Selenium.Firefox.FirefoxDriverService 服务,OpenQA.Selenium.Firefox.FirefoxOptions 选项,TimeSpan 命令超时)[0x00000] 中:0 在 OpenQA.Selenium.Firefox.FirefoxDriver..ctor (OpenQA.Selenium.Firefox.FirefoxOptions 选项)[0x00000] 中:0 在 OpenQA.Selenium.Firefox.FirefoxDriver..ctor () [0x00000] 中:0 在 Dialga.MyBot+c__async8.MoveNext () [0x00000] in :0

【问题讨论】:

  • 猜测你在 Pi 上的 Firefox 可执行文件的路径是错误的
  • 我对此表示怀疑,但我现在正在尝试以下路径:/usr/share/applications/firefox-esr.desktop
  • 我仍然遇到同样的错误,所以这并没有解决问题。 [又走错路了?]

标签: c# selenium-webdriver raspberry-pi connection connection-refused


【解决方案1】:

所以我让它工作了。它不能正常工作的原因是 Firefox 和 geckodriver 版本不匹配。 我通过下载 Firefox 52.2-ESR 并使用 geckdrover 1.7 解决了这个问题。 [硒 3.4]。

遗憾的是,Firefox 会降低树莓派的速度,所以我将其全部切换为 PhantomJS 网络驱动程序。

【讨论】:

    猜你喜欢
    • 2015-08-24
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 2014-10-03
    • 2014-10-24
    • 2021-04-13
    • 1970-01-01
    • 2013-12-12
    相关资源
    最近更新 更多