如何使用ChromeDriver 2.32和Chrome 57或更高版本下载PDF

时间:2017-09-19 08:43:34

标签: c# google-chrome pdf selenium-chromedriver

自Google第57版以来,Google确实删除了chrome://plugins选项。我发现如果我想下载PDF文件而不是在Chrome浏览器中打开它,我需要打开chrome://settings/content/pdfDocuments中的开关 enter image description here

有没有办法在Chrome驱动程序中设置此选项,例如使用下面的首选项?

private ChromeOptions BuildChromeProfile()
        {
            var options = new ChromeOptions();

            options.AddUserProfilePreference("download.default_directory", DownloadsPath);
            options.AddUserProfilePreference("download.prompt_for_download", false);
            return options;
        }

还是其他任何方式?

1 个答案:

答案 0 :(得分:0)

module.exports = {
commands: [sectionsCommand],
elements:{
    contentTypeNameElem:"div.content-type>div>div:nth-child(2)",
    sectionLinkElem:"div.sections div.section div.content>a",
    indicatorElem:"div.sections div.section div.content>div.indicators",
    mandatoryfldElem:"g[id^='Icons/Check']",
    springboardElem:"div[class='springboard--tabs']",
    sectionsPanelElem:"div[class='sections']",
    docSectionTblElem:"div.kix-page-content-wrapper table.kix-tablerenderer-table",
    docSectionsElement:"(//td[contains(.,'?')]/parent::tr/following::tr/td[contains(@style,'background-color: rgb(255, 255, 255)')])[1]",
    sectionCheckMarkElement:"(//a[normalize-space(text())='?']/parent::div//*[name()='g'])[last()]",
    docSectionTableElement:"(//td[starts-with(.,'?')]/parent::tr/ancestor::table)[1]",
    sectionButtonElement:{
        selector:"//button[contains(.,'?')]",
        locateStrategy:'xpath'
    },
    docSectionLastTDElement:"(//td[@class='kix-tablerenderer-td'])[last()]",
    attachmentlinkElement:"//a[text()='?']/following-sibling::div[@class='indicators']/span[1]",
    attachmentTypeElement:"//div[@class='section-item-menu']/ul/li[contains(.,'?')]",
    attchDiagHeaderElement:"//span[text()='?']"
},
sections: {
    addFigureAttachmentDialog: {
        selector:"#",
        elements: {
            attachmentdialogIframeElement:{
                selector:"//div[@class='modal-dialog docs-dialog script-app-dialog']//iframe",
                locateStrategy: 'xpath'    
            },
            titleInputElement:{
                selector:"//input[@id='title']",
                locateStrategy: 'xpath' 
            },
            CitationInputElement: {
                selector:"//input[@id='citation']",
                locateStrategy: 'xpath' 
            },
            NotesForDsgnrTxtAreatElement:{
                selector:"//textarea[@id='notes']",
                locateStrategy: 'xpath'
            },
            PathToSrcFileInputElement:{
                selector:"//input[@id='pathToSource']",
                locateStrategy: 'xpath'
            },
            PathToFinishedFgrInputElement:{
                selector:"//input[@id='pathToFinished']",
                locateStrategy: 'xpath'
            },
            AccsbltyDecrpTxtAreaElement:{
                selector:"//textarea[@id='description']",
                locateStrategy: 'xpath'
            }
        }
    }
}

为我工作。