0

我使用硒書寫了一個C# pogram。它在Windows上使用時效果很好,但不適用於Rapsberry Pi。 [它沒有硒部分]。使用單色的樹莓派上的硒(C#)

下面是代碼:

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.UnpackAndThrowOnErro找到一組匹配的功能 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(System.String driverCommandToExecute,System.Collections.Generic.Dictionary`2參數)[0x00000]中的[0x00000]:0 [0] [00000] 0 在OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)[0x00000]在:0 在OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor,ICapabilities desiredCapabilities)[0x00000]在:0 在OpenQA .Selenium.Firefox.FirefoxDriver..ctor(OpenQA.Selenium.Firefox.FirefoxDriverService服務,OpenQA.Selenium.Firefox.FirefoxOptions選項,TimeSpan commandTimeout)[0x00000]在:0 at OpenQA.Selenium.Firefox.FirefoxDriver..ctor( OpenQA.Selenium.Firefox.FirefoxOptions選項)[0x00000]:0 位於OpenQA.Selenium.Firefox.FirefoxDriver。 ()[0x00000] in:0 at Dialga.MyBot + c__async8.MoveNext()[0x00000] in:0

+0

猜測你在Pi上的Firefox可執行文件的路徑是錯誤的 –

+0

我懷疑它,但我現在正在嘗試以下路徑:/usr/share/applications/firefox-esr.desktop – Gami

+0

我仍然得到同樣的錯誤,所以這並沒有解決問題。 [再次錯誤路徑?] – Gami

回答

0

所以我得到了它的工作。它沒有正常工作的原因是Firefox和geckodriver版本不匹配。 我通過下載Firefox 52.2-ESR並使用geckdrover 1.7解決了這個問題。 [硒3.4]。

令人遺憾的是Firefox是在樹莓派上慢下來的,所以我把它換成了PhantomJS webdriver。