Selenium Firefox打开超时 [英] Selenium Firefox Open timeout
问题描述
当它工作时,代码执行速度非常快,页面加载.5秒。
然而,在3-5次迭代之后,会话似乎总是失败。打开命令将导致一个窗口被产生,但没有页面被加载。最终返回超时异常。该页面实际上没有超时。相反,它就好像对URL的请求从未到达浏览器窗口一样。
class Program
{
static void Main(string [] args)
{
for(int i = 0; i <10; i ++)
{
var s = new DefaultSelenium localhost,4444,firefox,http://my.server);
s.Start();
s.SetSpeed(300);
s.Open(/);
s.WaitForPageToLoad(30000);
s.Type(// input [contains(@id,'_username')],my.test);
s.Type(// input [contains(@id,'_password')],password);
s.Stop();
$ b 解决方法我面临同样的问题,这是因为DefaultSelenium的打开方法的超时时间为30000ms,因此等待30秒才能加载页面。你可以试试这个简单的解决方案。
// selenium是DefaultSelenium实例作为类的私有成员
布尔serverStartTry = false;
int tryCount = 1; ((!!serverStartTry)&& tryCount< = Constants.maxServerTries)
{
try {
this.selenium.open(ReadConFile.readcoFile(pageName ));
System.out.println(服务器启动尝试否:+ tryCount);
serverStartTry = true;
catch(SeleniumException e){
System.out.println(Server start try no:+ tryCount);
System.out.println(Server Start Try:+ serverStartTry);
serverStartTry = false;
tryCount ++;
$ b if(!serverStartTry){
System.out.println(Server Not started,no。of attempts made:+ tryCount);
System.exit(0);
}
Using Windows 2008, C#, Firefox 3.5.1, Selenium RC (v1.0.1)
When it works, this code executes very quickly and the page loads within .5 seconds.
However, the session always seems to fail after 3 - 5 iterations. The open command will cause a window to be spawned, but no page to be loaded. Eventually a timeout exception is returned. The page has not actually timed out. Instead, it is as though the request for a URL has never reached the browser window.
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
var s = new DefaultSelenium("localhost", 4444, "firefox", "http://my.server");
s.Start();
s.SetSpeed("300");
s.Open("/");
s.WaitForPageToLoad("30000");
s.Type("//input[contains(@id, '_username')]", "my.test");
s.Type("//input[contains(@id, '_password')]", "password");
s.Stop();
}
}
}
解决方案 I was facing the same problem .This is because open method of DefaultSelenium has timeout of 30000ms, so it waits for 30s for your page to load. You can try this trivial solution.
//selenium is DefaultSelenium instance as private member of the class
boolean serverStartTry = false;
int tryCount =1;
while((!serverStartTry) && tryCount <= Constants.maxServerTries){
try{
this.selenium.open(ReadConFile.readcoFile("pageName"));
System.out.println("Server started in try no: "+tryCount);
serverStartTry =true;
}catch (SeleniumException e) {
System.out.println("Server start try no: "+tryCount );
System.out.println("Server Start Try: "+ serverStartTry);
serverStartTry = false;
tryCount++;
}
}
if(!serverStartTry){
System.out.println("Server Not started, no. of attempts made: "+tryCount);
System.exit(0);
}
这篇关于Selenium Firefox打开超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!