簡體   English   中英

這是什么類型的窗口,我如何用 Selenium 處理它? 自動?

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

我有一個 Windows Detective 聲稱是“MozillaDialogClass”窗口的對話框,當然我現在正在 Firefox 中進行測試。

這是窗口的圖像。

在此處輸入圖片說明

AutoIt IDE 無法識別它。 Windows Defender 看不到它的任何屬性,所以我不知道它的名稱是什么或關於它的任何其他信息。 其中一位開發人員說這是一個特定於瀏覽器的窗口。 (不管那是什么,如果是這樣,為什么什么都看不到它?)。

有沒有人對此有任何想法? 我難住了。

處理這個問題的最好方法是使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM