Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

sikuli x - Can we handle download pdf files instead of automatically opening in chrome by using Serenity

I tried to enable download pdf files instead of automatically opening in chrome using selenium and sikulix successfully.

But I'm using serenity and facing the below issues during download

  1. I cannot set preferences for auto download using serenity
  2. I tried to implement the sikulix script to enable but getting ExceptionInInitializerError on pattern class (able to enable using selenium with sikuli)

public void test() throws FindFailed, InterruptedException { //WebDriverManager.chromedriver().arch64().setup();

    System.setProperty("webdriver.chrome.driver", ".\Drivers\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-extensions");
    options.addArguments("ignore-certificate-errors");
    driver = new ChromeDriver(options);
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    Screen s = new Screen();
    System.out.println(System.getProperty("user.dir")+"\Images\DownloadPdfView.PNG");
    Pattern fileInputTextBox = new Pattern(System.getProperty("user.dir")+"\Images\DownloadPdfView.PNG");
    Pattern openButton = new Pattern(System.getProperty("user.dir")+"\Images\DownloadPdf.PNG");
    
    driver.navigate().to("chrome://settings/content/pdfDocuments");
    
    s.wait(fileInputTextBox, 20);
    s.click(openButton);
    Thread.sleep(8000);
    Pattern open = new Pattern(System.getProperty("user.dir")+"\Images\DownladEnabledButton.PNG");
    System.out.println(s.exists(open));
     
    driver.quit();
}

3. I tried with AutoIT but unable to click on enable button

public void testAutoIT() throws InterruptedException {
        //WebDriverManager.chromedriver().arch64().setup();
        
        System.setProperty("webdriver.chrome.driver", ".\Drivers\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-extensions");
        options.addArguments("ignore-certificate-errors");
        driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.navigate().to("chrome://settings/content/pdfDocuments");
        
        try {
            System.out.println(System.getProperty("user.dir")+"\AutoIT\pdfHandler.exe");
            Runtime.getRuntime().exec(System.getProperty("user.dir")+"\AutoIT\pdfHandler.exe");
            System.out.println("Okay");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Thread.sleep(8000);
        driver.quit();
    }

WinWait("Settings - PDF documents - Google Chrome","",15)
If WinExists("Settings - PDF documents - Google Chrome") Then
    WinActivate("Settings - PDF documents - Google Chrome")
    Sleep(10)
    Send("{ENTER}")
    ControlClick("Settings - PDF documents - Google Chrome","","Chrome_RenderWidgetHostHWND1")
EndIf
question from:https://stackoverflow.com/questions/65867251/can-we-handle-download-pdf-files-instead-of-automatically-opening-in-chrome-by-u

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...