[英]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.