C# Selenium-无法连接到远程服务器
让我先告诉你这个错误,然后我将解释上下文,最后我将展示代码并解释它 错误 下面是使用FirefoxDriver时出现的相同/类似错误 上下文 我做了一个程序,通过网站收集一些数据。此程序在我的本地桌面windows 7 professional上100%运行,但当我将其移动到我的服务器时,它会抛出上述错误 注意,应用程序是多线程的,在上面的例子中,有两个线程运行2个selenium实例。当他们收集完想要浏览的链接列表时,应用程序就会出现问题。一个线程将一个接一个地查找和浏览链接列表,当另一个线程收集完它想要浏览的链接后,两个selenium客户端都会中断并开始抛出上面的错误 我没有使用任何不适用于.net framework 3.5的函数。。。。一切都是标准化的,以适应2003服务器(至少据我所知) 代码 收集链接时:C# Selenium-无法连接到远程服务器,c#,selenium,selenium-webdriver,selenium-firefoxdriver,C#,Selenium,Selenium Webdriver,Selenium Firefoxdriver,让我先告诉你这个错误,然后我将解释上下文,最后我将展示代码并解释它 错误 下面是使用FirefoxDriver时出现的相同/类似错误 上下文 我做了一个程序,通过网站收集一些数据。此程序在我的本地桌面windows 7 professional上100%运行,但当我将其移动到我的服务器时,它会抛出上述错误 注意,应用程序是多线程的,在上面的例子中,有两个线程运行2个selenium实例。当他们收集完想要浏览的链接列表时,应用程序就会出现问题。一个线程将一个接一个地查找和浏览链接列表,当另一个
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);
}
可能存在疑问的一些代码:
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!错误似乎只出现在链接收集和数据收集之间,或者在数据收集开始时。有两个线程,它们可以在本地Windows7桌面上正常工作。如果程序重新启动,它将加载一个保存的链接,并将使用这些保存的链接而不会显示错误当浏览器未显示为顶部屏幕时,会发生此错误。所以如果你把它最小化,这最终会发生
到目前为止还没有解决方案。有关此问题的更新,请参阅 当浏览器未显示为顶部屏幕时,会发生此错误。所以如果你把它最小化,这最终会发生 到目前为止还没有解决方案。有关此问题的更新,请参阅
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;
}