硒C#接受确认框 [英] Selenium c# accept confirm box

查看:229
本文介绍了硒C#接受确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了使用C#中硒的NUnit测试。

I have written an nUnit test using selenium in c#.

所有进行得很顺利,直到我必须确认一个JS确认框。

All was going well until I have to confirm a JS confirm box.

下面是我使用的代码:

this.driver.FindElement(By.Id("submitButton")).Click();
this.driver.SwitchTo().Alert().Accept();

的确认框提交按钮后出现。在确认出现,然后立即消失,但形式不提交。该行为是相同的,无论上面的接受()行。

The confirm box appears after the submit button. The confirm appears and then disappears immediately but the form does not submit. The behaviour is the same regardless of the accept() line above.

我使用的是Firefox v15.0.1和硒v2.24

I am using Firefox v15.0.1 and selenium v2.24

我试图把之间的点击提交和确认接受了Thread.Sleep。

I have tried putting a Thread.Sleep between the submit click and the confirm accept.

我已阅读一切都已经表示,硒驱动程序会自动将发送确认OK,但别的东西似乎发生。

Everything I have read has said that the selenium driver will automatically send a confirm OK, but something else seems to be happening.

推荐答案


它是这样的:

in this issue i would try to verify confirm box presence. it be something like:

this.driver.FindElement(By.Id("submitButton")).Click();


 boolean presentFlag = false;

  try {

   // Check the presence of alert
   Alert alert = driver.switchTo().alert();
   // Alert present; set the flag
   presentFlag = true;
   // if present consume the alert
   alert.accept();

  } catch (NoAlertPresentException ex) {
   // Alert not present
   ex.printStackTrace();
  }

  return presentFlag;

 }



那么,如果doen't工作。尝试调试一步一步来。
一些附加的有关信息警报(确认框)中硒处理这里
希望这在某种程度上可以帮助你。

then if doen't work. try to debug step by step. some additional info concerning alert ( confirm boxes) handle in selenium here hope this somehow helps you

这篇关于硒C#接受确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆