与Selenium的模态对话窗口 [英] Modal Dialog window with Selenium

查看:394
本文介绍了与Selenium的模态对话窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我尝试使用Selenium导航到IE9中的页面,在加载页面时,表示存在证书错误。使用AutoIT我可以让它在浏览器中单击,然后TAB两次然后按Enter键,没有问题。但是当它继续时,它会抛出模态对话框存在错误。以下是应该处理IE安全警告错误的方法:

So I'm trying to navigate to a page in IE9 using Selenium that, when loading the page, says there is a certificate error. Using AutoIT I'm able to get it to click within the browser and then TAB twice then hit enter, no problems. However when it continues, it throws a "Modal dialog present error". Here's the method that is to supposed to handle IE Security Warning errors:

# Handle IE Security Warning errors.
class  Selenium::WebDriver::Navigation
  def to(url)
  @bridge.get url
  if @bridge.getTitle.match(/Certificate Error.*/)
      Thread.new do
        sleep 0.75
        security_warning = 'Security Warning'
        if @auto_it.WinActive(security_warning)
             @auto_it.ControlClick(security_warning, "Yes", '[CLASS:Button; INSTANCE:2]' )
      end
       auto_it = WIN32OLE.new("AutoItX3.Control")
       auto_it.WinWait('[CLASS:IEFrame]','', 90)
       x = auto_it.WinGetPosX('[CLASS:IEFrame]') 
       y = auto_it.WinGetPosY('[CLASS:IEFrame]')
       auto_it.MouseClick("left", x + 100, y + 200, 1, 0) 
       auto_it.Send "{TAB 2}{ENTER}"
       sleep 0.25
       wait.until { @bridge.executeScript("return document.readyState;") == "complete" }
    end
  end
end

我能在这里做的最好的是睡眠0.25呼叫要做到这一点:

The best that I can do here is below the "sleep 0.25" call is to do this:

auto_it.Send "{TAB}{ENTER}"

(除了{ENTER}没有做任何事情,它只会挂起,直到测试超时)

(Except the {ENTER} doesn't do anything, it just hangs there until the test times out)

我需要知道如何让Selenium与弹出的对话框交互。我知道Selenium不能很好地处理它们(这就是使用AutoIT的原因)。有什么想法?

I need to know how to get Selenium to interface with that dialog box that pops up. I know that Selenium doesn't handle them very well (which is why AutoIT is being used). Any ideas?

P.S。这不是我的代码,这个方法是由我的同事创建的

P.S. This is not my code, This method was created by my co-worker

推荐答案

如果这是典型的SSL证书错误警告显示在IE,然后您可能想使用JavascriptExecutor来处理它,如本博客文章中详细描述的那样:

If this is typical SSL certificate error warning displayed in IE, then you may want to use JavascriptExecutor to handle it, as described in detail in this blog post:

http://automatictester.co.uk/2014/08/03/handling-ssl-certificate-errors -in-selenium /

一般来说,尽量避免将AutoIT与Selenium混合使用,除非你真的需要。

In general, try to avoid mixing AutoIT with Selenium, unless you really have to.

这篇关于与Selenium的模态对话窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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