带有 Selenium 的模态对话框窗口 [英] Modal Dialog window with Selenium

查看:40
本文介绍了带有 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

我在这里能做的最好的事情是在sleep 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. This is not my code, This method was created by my co-worker

推荐答案

如果这是 IE 中显示的典型 SSL 证书错误警告,那么您可能需要使用 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天全站免登陆