Could anyone give me a hand here? I need to verify the contents of a pdf file. So, I click on a button to open a pdf file which opens in a new tab. And, I need to verify the contents. I have given below the sample code which works in 'non-headless' mode (Chrome), but not in 'headless' which is what I want. I use Java and the plugin used is pdfBox. The error I get is " org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died." The error points to this line of code --> URL url = new URL(webDriver.getCurrentUrl());
webDriver.get("https://irl.umsl.edu/oer/24/"); //Below link opens in a new tab
webDriver.findElement(By.xpath("//a[normalize-space()='Download']")).click();
ArrayList<String> tabs = new ArrayList<String>(webDriver.getWindowHandles());
webDriver.switchTo().window(tabs.get(1));
URL url = new URL(webDriver.getCurrentUrl());
InputStream in = url.openStream();
BufferedInputStream bf = new BufferedInputStream(in);
PDDocument doc = PDDocument.load(bf);
String content = new PDFTextStripper().getText(doc);
Assert.assertTrue(content.contains("Intercultural Communication"));