0
當我點擊一個鏈接時,pdf將在瀏覽器中打開。我的測試要求我將pdf保存到桌面上。Watir - 在html中打開文件時如何保存pdf文件
我能找到打開pdf但無法保存的新窗口。至於保存PDF,我必須將鼠標懸停在底部以獲取PDF圖標,否則我將不得不去文件 - >另存爲以保存PDF。
當我點擊一個鏈接時,pdf將在瀏覽器中打開。我的測試要求我將pdf保存到桌面上。Watir - 在html中打開文件時如何保存pdf文件
我能找到打開pdf但無法保存的新窗口。至於保存PDF,我必須將鼠標懸停在底部以獲取PDF圖標,否則我將不得不去文件 - >另存爲以保存PDF。
這裏是你如何能做到在Firefox
download_directory = "#{Dir.pwd}/downloads"
download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.folderList'] = 2 # custom location
profile['browser.download.dir'] = download_directory
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"
b = Watir::Browser.new :firefox, :profile => profile
和Chrome
download_directory = "#{Dir.pwd}/downloads"
download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = download_directory
b = Watir::Browser.new :chrome, :profile => profile
與也就是說你可能會做這樣的事情sample code:
f = open('sample.pdf')
begin
http.request_get('/sample.pdf') do |resp|
resp.read_body do |segment|
f.write(segment)
end
end
ensure
f.close()
end
我需要這個IE瀏覽器。讓我知道是否有任何方法。 – user3794809
請參閱編輯答案 –
我嘗試使用文件 - >保存AS工具欄保存PDF。所以發送鑰匙點擊文件 - >另存爲 – user3794809