[英]What kind of window is this and how do I handle it with Selenium? Autoit?
处理这个问题的最好方法是使用SikuliX 。 以下是使用 SikuliX 的示例场景。 基本上,SikuliX 可以自动化您在运行 Windows、Mac 或某些 Linux/Unix 的台式计算机屏幕上看到的任何内容。 它使用由 OpenCV 提供支持的图像识别来识别和控制 GUI 组件。 如果无法轻松访问 GUI 的内部结构或要操作的应用程序或网页的源代码,这将非常方便。
下面是一个 hello world 示例。 单击屏幕上的聚光灯图标,等待聚光灯的输入窗口出现,然后键入“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();
}
}
}
你可以在 这里找到sikuli
这是来自您的网络浏览器的本机对话框。 所以用Selenium处理这个并不容易。 你想在里面测试什么?
对于一些阅读,另见这个问题: https : //sqa.stackexchange.com/questions/2197/how-to-download-a-file-using-seleniums-webdriver
您可以将 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();
或者使用默认应用程序自动打开文件:
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();
请注意,您需要通过您的文件之一更新 MIME 类型(此处为application/vnd.ms-excel
)。 MIME 类型是来自响应头的Content-Type
。
如果你只想关闭对话框,那么我会使用 AutoIt:
WinWait("[CLASS:MozillaDialogClass]", "", 10)
WinClose("[CLASS:MozillaDialogClass]")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.