如何解决如何使用Selenium和GeckoDriverFirefox直接下载多个文件
我有一个Web服务,当调用它时,它会提供csv文件(MIME application/x-excel
)和以下Kotlin代码(仅相关片段):
System.setProperty(
"webdriver.gecko.driver","D:\\Programme\\geckodriver-v0.27.0-win64\\geckodriver.exe")
val profile = FirefoxProfile()
profile.setPreference("browser.download.folderList",2)
profile.setPreference("browser.download.manager.showWhenStarting",false)
profile.setPreference("browser.download.manager.closeWhenDone",true)
profile.setPreference("browser.download.dir",outputDir.absolutePath)
profile.setPreference(
"browser.helperApps.neverAsk.saveToDisk","application/x-excel")
val options = FirefoxOptions()
options.profile = profile
driver = FirefoxDriver(options)
urlsForMonth.forEachIndexed { index,uri ->
log.info("$uri")
driver.get(uri) // first get works fine,but never returns
log.info("Done") // never comes to this line
}
第一个文件下载正常,但随后发生超时。第二条日志行未触发。我已经知道driver.get()
已用于导航到URL并等到页面加载完毕(触发了onLoad)。因此,这解释了行为。但是driver.navigate().to()
不应该等待页面加载,也不要从调用返回。
当我在服务器主页上跳出循环然后执行navigate().to()
进行下载时,我能够下载文件1(发生完成的日志行),然后挂在第二个文件上navigate().to()
通话。
任何人都可以给我提示我缺少什么吗?
org.openqa.selenium.TimeoutException: Timeout loading page after 300000ms
Build info: version: '3.141.59',revision: 'e82be7d358',time: '2018-11-14T08:17:03'
System info: host: 'bla',ip: '10.35.60.213',os.name: 'Windows 10',os.arch: 'amd64',os.version: '10.0',java.version: '11.0.2'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true,browserName: firefox,browserVersion: 68.6.1,javascriptEnabled: true,moz:accessibilityChecks: false,moz:buildID: 20200403065309,moz:geckodriverVersion: 0.27.0,moz:headless: false,moz:processID: 21068,moz:profile: C:\Users\myself\AppData\Lo...,moz:shutdownTimeout: 60000,moz:useNonSpecCompliantPointerOrigin: false,moz:webdriverClick: true,pageLoadStrategy: normal,platform: WINDOWS,platformName: WINDOWS,platformVersion: 10.0,rotatable: false,setWindowRect: true,strictFileInteractability: false,timeouts: {implicit: 0,pageLoad: 300000,script: 30000},unhandledPromptBehavior: dismiss and notify}
Session ID: d1d6ec79-13e9-4fa0-9560-da0112966fe4
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。