Hello, I’m using a private website, trying to count the number of pages of a PDF file.
I have come to the conclusion that I need to download the file and then to count it’s pages using PDFBox :
File file = new File(pdfFilePath)
PDDocument pdfDoc = PDDocument.load(file)
int pageCount = pdfDoc.getNumberOfPages()
The fact is, I don’t know how to download the file, when I click on download button on the Website, it opens the pdf in a new browser tab (that’s the problem). Also I’d like to download directly to my Project data files to keep portability of my project.
So I tried doing “ctrl + S” to open register manager, but it doesn’t work apparently :
For the above issue, have you tried the below. Just a note that others suggest putting a WAIT, or delay, just before you switch to allow time for the statement to determine the new tab’s existence and index.
'Switch to new browser tab'
WebUI.switchToWindowIndex(1)
I would assume a similar example works for edge, to be run in proper test listener Before testcase (so before the browser is opened). Note that there might also be some deviations in setting these in Katalon v10.0.0 (see Migrate Katalon Studio from 9.x to 10.0.0 | Katalon Docs ).
import com.kms.katalon.core.configuration.RunConfiguration
// Get the current project directory
String projectDir = RunConfiguration.getProjectDir()
// Set the relative path for the download directory
String downloadDir = projectDir + "/Downloads"
// Set the desired capabilities for Edge
Map<String, Object> edgePrefs = new HashMap<String, Object>()
edgePrefs.put("download.default_directory", downloadDir)
edgePrefs.put("download.prompt_for_download", false)
edgePrefs.put("plugins.always_open_pdf_externally", true)
Map<String, Object> edgeOptions = new HashMap<String, Object>()
edgeOptions.put("prefs", edgePrefs)
RunConfiguration.setWebDriverPreferencesProperty("edgeOptions", edgeOptions)