简体   繁体   English

这是什么类型的窗口,我如何用 Selenium 处理它? 自动?

[英]What kind of window is this and how do I handle it with Selenium? Autoit?

I have a dialog that Windows Detective claims is a "MozillaDialogClass" window, I'm testing in Firefox right now of course.我有一个 Windows Detective 声称是“MozillaDialogClass”窗口的对话框,当然我现在正在 Firefox 中进行测试。

Here is an image of the window.这是窗口的图像。

在此处输入图片说明

AutoIt IDE doesn't recognize it. AutoIt IDE 无法识别它。 Windows Defender can't see any of it's properties so I have no idea what the name of it is or anything else about it. Windows Defender 看不到它的任何属性,所以我不知道它的名称是什么或关于它的任何其他信息。 One of the developers says it's a browser specific window.其中一位开发人员说这是一个特定于浏览器的窗口。 (whatever the heck that is, if it is why can't anything see it?). (不管那是什么,如果是这样,为什么什么都看不到它?)。

Anyone have any ideas on this one?有没有人对此有任何想法? I'm stumped.我难住了。

The best way to handle this is to use SikuliX .处理这个问题的最好方法是使用SikuliX Below is an example scenario using SikuliX.以下是使用 SikuliX 的示例场景。 Basically, SikuliX automates anything you see on the screen of your desktop computer running Windows, Mac or some Linux/Unix.基本上,SikuliX 可以自动化您在运行 Windows、Mac 或某些 Linux/Unix 的台式计算机屏幕上看到的任何内容。 It uses image recognition powered by OpenCV to identify and control GUI components.它使用由 OpenCV 提供支持的图像识别来识别和控制 GUI 组件。 This is handy in cases when there is no easy access to a GUI's internals or the source code of the application or web page you want to act on.如果无法轻松访问 GUI 的内部结构或要操作的应用程序或网页的源代码,这将非常方便。

Below is a hello world example.下面是一个 hello world 示例。 This clicks on the spotlight icon on the screen, waits spotlight's input window appears, and then types “hello world” and hits ENTER.单击屏幕上的聚光灯图标,等待聚光灯的输入窗口出现,然后键入“hello world”并按 ENTER。

import org.sikuli.script.*;

public class TestSikuli {

    public static void main(String[] args) {
            Screen s = new Screen();
            try{
                    s.click("imgs/spotlight.png", 0);
                    s.wait("imgs/spotlight-input.png");
                    s.type(null, "hello world\n", 0);
            }
            catch(FindFailed e){
                    e.printStackTrace();
            }

    }

 }

You can find sikuli here你可以在 这里找到sikuli

This is a native Dialog from your webbrowser.这是来自您的网络浏览器的本机对话框。 So it is not easy to handle this with Selenium.所以用Selenium处理这个并不容易。 What do you want to test in it?你想在里面测试什么?

For some reading, see also this question: https://sqa.stackexchange.com/questions/2197/how-to-download-a-file-using-seleniums-webdriver对于一些阅读,另见这个问题: https : //sqa.stackexchange.com/questions/2197/how-to-download-a-file-using-seleniums-webdriver

Rather than handling the download window, you could setup Firefox to automatically download the file to a folder:您可以将 Firefox 设置为自动将文件下载到文件夹,而不是处理下载窗口:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("pdfjs.disabled", true);  // disable the built-in viewer
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", "C:\\Windows\\temp");
profile.setPreference("browser.download.panel.shown", false);
profile.setPreference("browser.helperApps.neverAsk.openFile", "");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel");

WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.exinfm.com/free_spreadsheets.html");
driver.findElement(By.linkText("Capital Budgeting Analysis")).click();

Or to automatically open a file with the default application:或者使用默认应用程序自动打开文件:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("pdfjs.disabled", true);  // disable the built-in viewer
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.panel.shown", false);
profile.setPreference("browser.helperApps.neverAsk.openFile", "application/vnd.ms-excel");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "");

WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.exinfm.com/free_spreadsheets.html");
driver.findElement(By.linkText("Capital Budgeting Analysis")).click();

Note that you need to update the MIME type ( application/vnd.ms-excel here) by the one of your file.请注意,您需要通过您的文件之一更新 MIME 类型(此处为application/vnd.ms-excel )。 The MIME type is the Content-Type from the response header. MIME 类型是来自响应头的Content-Type

And if you just want to close the dialog, then I would use AutoIt:如果你只想关闭对话框,那么我会使用 AutoIt:

WinWait("[CLASS:MozillaDialogClass]", "", 10)
WinClose("[CLASS:MozillaDialogClass]")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎么知道这是一种什么样的方法? - how do i know what kind of method is this? 如何在watchservice中正确处理pollEvents()溢出类型? - How do I properly handle pollEvents() overflow kind in a watchservice? (StaleElementException:Selenium)我该如何处理? - (StaleElementException:Selenium) How do I handle this? 如何在Selenium Webdriver中安全处理弹出窗口 - How can I handle popup window safely in selenium webdriver 如何使用Java在Selenium中选择一个窗口? - How do I select a window in Selenium with Java? 我如何处理对话框窗口以单击Selenium Webdriver中的按钮 - How Can I handle dialog window to click on button in selenium webdriver 如何在没有 autoit 和 url 方法的情况下使用 java 处理带有 selenium webdriver 的浏览器的身份验证警报 - How to handle authentication alert of browser with selenium webdriver using java without autoit and url method 如何参数化 AutoIt 脚本以处理跨浏览器 window 弹出标题和文件? - How to parametrize an AutoIt script to handle cross-browser window popup titles and files? 我要使用哪种SSL实施? - What kind of SSL implementation do I go for? 如何使用Selenium WebDriver处理HtmlUnitDriver的身份验证? - How do I handle authentication with the HtmlUnitDriver using Selenium WebDriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM