<i id='5ZzCz'><tr id='5ZzCz'><dt id='5ZzCz'><q id='5ZzCz'><span id='5ZzCz'><b id='5ZzCz'><form id='5ZzCz'><ins id='5ZzCz'></ins><ul id='5ZzCz'></ul><sub id='5ZzCz'></sub></form><legend id='5ZzCz'></legend><bdo id='5ZzCz'><pre id='5ZzCz'><center id='5ZzCz'></center></pre></bdo></b><th id='5ZzCz'></th></span></q></dt></tr></i><div id='5ZzCz'><tfoot id='5ZzCz'></tfoot><dl id='5ZzCz'><fieldset id='5ZzCz'></fieldset></dl></div>

    <small id='5ZzCz'></small><noframes id='5ZzCz'>

  1. <legend id='5ZzCz'><style id='5ZzCz'><dir id='5ZzCz'><q id='5ZzCz'></q></dir></style></legend>

    • <bdo id='5ZzCz'></bdo><ul id='5ZzCz'></ul>

      <tfoot id='5ZzCz'></tfoot>

      Selenium c#接受确认框

      Selenium c# accept confirm box(Selenium c#接受确认框)

          <tbody id='96m1M'></tbody>
        <tfoot id='96m1M'></tfoot>
          <legend id='96m1M'><style id='96m1M'><dir id='96m1M'><q id='96m1M'></q></dir></style></legend>

              <bdo id='96m1M'></bdo><ul id='96m1M'></ul>
              • <small id='96m1M'></small><noframes id='96m1M'>

              • <i id='96m1M'><tr id='96m1M'><dt id='96m1M'><q id='96m1M'><span id='96m1M'><b id='96m1M'><form id='96m1M'><ins id='96m1M'></ins><ul id='96m1M'></ul><sub id='96m1M'></sub></form><legend id='96m1M'></legend><bdo id='96m1M'><pre id='96m1M'><center id='96m1M'></center></pre></bdo></b><th id='96m1M'></th></span></q></dt></tr></i><div id='96m1M'><tfoot id='96m1M'></tfoot><dl id='96m1M'><fieldset id='96m1M'></fieldset></dl></div>

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

                问题描述

                我在 c# 中使用 selenium 编写了一个 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.

                这是我正在使用的代码:

                here is the code I am using:

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

                确认框出现在提交按钮之后.确认出现然后立即消失,但表单未提交.无论上面的 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 和 selenium 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;
                
                 }
                

                如果不工作.尝试逐步调试.关于 selenium 中的警报(确认框)句柄的一些附加信息这里希望这对您有所帮助

                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

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

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                How to store delegates in a List(如何将代表存储在列表中)
                How delegates work (in the background)?(代表如何工作(在后台)?)
                C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)

                    1. <legend id='gYbL6'><style id='gYbL6'><dir id='gYbL6'><q id='gYbL6'></q></dir></style></legend>
                        <tbody id='gYbL6'></tbody>
                      <tfoot id='gYbL6'></tfoot>

                      <small id='gYbL6'></small><noframes id='gYbL6'>

                          <bdo id='gYbL6'></bdo><ul id='gYbL6'></ul>
                        • <i id='gYbL6'><tr id='gYbL6'><dt id='gYbL6'><q id='gYbL6'><span id='gYbL6'><b id='gYbL6'><form id='gYbL6'><ins id='gYbL6'></ins><ul id='gYbL6'></ul><sub id='gYbL6'></sub></form><legend id='gYbL6'></legend><bdo id='gYbL6'><pre id='gYbL6'><center id='gYbL6'></center></pre></bdo></b><th id='gYbL6'></th></span></q></dt></tr></i><div id='gYbL6'><tfoot id='gYbL6'></tfoot><dl id='gYbL6'><fieldset id='gYbL6'></fieldset></dl></div>