[英]Selenium's remote web driver for firefox cannot connect - FF 26 and Selenium Server 2.39
[英]Selenium - Cannot Connect to Remote Server
讓我首先為您提供錯誤信息,然后再解釋上下文,最后展示代碼並進行解釋。
上下文
我制作了一個程序來瀏覽網站並收集一些數據。 該程序在我的本地桌面Windows 7 Professional上可以100%運行,但是當我將其移動到服務器上時,該服務器是帶有.net Framework 3.5的Windows 2003服務器,它將引發上述錯誤。
請注意,在上述情況下,應用程序是多線程的,有兩個線程運行2個selenium實例。 當他們完成要瀏覽的鏈接列表的收集時,應用程序就會出現問題。 一個線程將一個接一個地查找並瀏覽鏈接列表,當另一個線程完成收集鏈接時,它希望探索兩個硒客戶端中斷並開始拋出上述錯誤。
我沒有使用非.NET Framework 3.5的任何功能。...一切都經過標准化以適合2003服務器(至少據我所知)。
碼
收集鏈接時:
List<string> totalList = new List<string>();
if (loadedSave == null)
{
webManager.driver.Navigate().GoToUrl(getOffenderListURL(countyId));
for (int l = 2; l < 10000; l++)
{
try
{
var element1 = new WebDriverWait(webManager.driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists((By.XPath(getOffenderxPath(l)))));
string linkToOffender = element1.GetAttribute("href");
string offenderId = linkToOffender.Substring(linkToOffender.IndexOf('=') + 1);
if (totalList.Contains(offenderId))
{
continue;
}
totalList.Add(offenderId);
//----- ^^^^^ Add the links/ids to a list for later-----
}
catch (Exception e)
{
// ignore this error catch.... its not relevant
if (totalList.Count < 5 && countyId != 21)
{
if (Program.SiteDownCounter < 4)
{
if (Program.LastDown != DateTime.MinValue)
{
if ((DateTime.Now - Program.LastDown).TotalMinutes > 30)
{
Program.sendMail("NY State website seems to be down... will suspend action for 30 minutes. Current time: " + DateTime.Now, "NY State Site Down!");
Program.LastDown = DateTime.Now;
Program.SiteDownCounter++;
for (int x = 0; x < 30; x++)
Thread.Sleep(1000);
}
else
{
Thread.Sleep((1800 - (int)((DateTime.Now - Program.LastDown).TotalSeconds)) * 1000);
}
}
else
{
Program.sendMail("NY State website seems to be down... will suspend action for 30 minutes. Current time: " + DateTime.Now, "NY State Site Down!");
Program.LastDown = DateTime.Now;
Program.SiteDownCounter++;
for (int x = 0; x < 30; x++)
Thread.Sleep(1000);
}
}
else
{
start = false;
break;
}
continue;
}
break;
}
}
}
else
{
if (loadedSave.CompletedList != null)
totalList = loadedSave.CompletedList;
else
{
Console.WriteLine("The hell?");
}
}
Program.LastDown = DateTime.MinValue;
Program.SiteDownCounter = 0;
ScrapeLogic(countyId, out2, loadedSave, totalList);
}
完成收集鏈接后:
private void ScrapeLogic(int countyId, string value, ScraperStateSave LoadedSaveState, List<string> total)
{
ScraperStateSave saveState = new ScraperStateSave();
saveState.CountyId = countyId;
int totalCompletedCount = (LoadedSaveState != null ? LoadedSaveState.CompletedCount : 0);
int instanceCompletedCount = 0;
for (int l = totalCompletedCount; l < total.Count; l++)
{
try
{
if (Program.SiteDownCounter >= 3)
throw new Exception("Shutdown");
webManager.driver.Navigate().GoToUrl(getOffenderLinkById(total[l]));
string offenderId = total[l];
var currentPlacement = webManager.getElementTextByxPath(currentPlacementxPath, true);
Boolean wanted = false;
try
{
IWebElement wantedLabel = webManager.driver.FindElement(By.XPath("//*[@id=\"mainContent\"]/h3[2]"));
wanted = true;
}
catch (NoSuchElementException)
{
}
var lastName = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 2));
var firstName = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 3));
var middleName = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 4));
var dob = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 5));
var sex = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 6));
var riskLevel = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 7));
var designation = webManager.getElementTextByxPath(getOffenderInfoBasic(1, 8));
....and more of the same
線程如何啟動:
public NYScaper(Boolean local, Boolean quiet, int id)
{
this.localScrape = local;
this.threadId = id;
this.quiet = quiet;
Thread t = new Thread(doScrape);
t.Start();
}
一些可能有問題的代碼:
public IWebElement getElementByxPath(string xpath)
{
return driver.FindElement(By.XPath(xpath));
}
public string getElementTextByxPath(string xpath)
{
return driver.FindElement(By.XPath(xpath)).Text;
}
public string getElementTextByxPath(string xpath, Boolean wait)
{
return new WebDriverWait(driver, TimeSpan.FromSeconds(2)).Until(ExpectedConditions.ElementExists((By.XPath(xpath)))).Text;
}
主要問題/概述:
在Windows 7 Professional上有效,但在2003 Server上無效! 錯誤似乎只出現在鏈接收集和數據收集之間或數據收集開始時。 有兩個線程,它們可以在本地Windows 7桌面上正常工作。 如果程序重新啟動,它將加載鏈接的保存,並且將與那些保存的鏈接一起工作,而不會顯示錯誤!
當瀏覽器未顯示為頂部屏幕時,會發生此錯誤。 因此,如果將其最小化,則最終會發生這種情況。
到目前為止,尚無解決方案,有關此問題的更新,請參閱https://code.google.com/p/selenium/ 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.