- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Stackoverflow 中提出了许多与此类似的问题。但这是不同的我现在正在自动化一个网络应用程序,在应用程序结束时,将生成 PDF(它将显示为链接,单击它 PDF 将在新窗口中打开)。我现在正在使用 AUTOIT 来自动化“另存为”对话框。有没有其他方法可以不使用 AutoIT 来下载。
我尝试从标签下的应用程序中的链接获取PDF URL,但它实际上是调用JS在新窗口中打开PDF在新窗口中,PDF实际上位于嵌入标签中,其中src是关于::空白我获取了 PDF 完整的 src,但是当我在没有清除任何 cookie 的情况下使用该 URL 时,我无法获取 PDF
对于这个问题有什么建议吗?
最佳答案
使用ROBOT类上传文件
public String imagePath = System.getProperty("user.dir") +"\\src\\test\\java\\filepath.pdf";
public void uploadFileWithRobot(String imagePath) {
StringSelection stringSelection = new StringSelection(imagePath);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
robot.delay(250);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.delay(150);
robot.keyRelease(KeyEvent.VK_ENTER);
}
现在单击 PDF 并在新窗口中打开,然后验证 PDF 中是否存在文本
public String readPDFInURL(String text) throws EmptyFileException, IOException {
System.out.println("Enters into READ PDF");
String output = "";
URL url = new URL(driver.getCurrentUrl());
System.out.println("url : " + url);
InputStream is = url.openStream();
BufferedInputStream fileToParse = new BufferedInputStream(is);
PDDocument document = null;
try {
document = PDDocument.load(fileToParse);
output = new PDFTextStripper().getText(document);
if (output.contains(text)) {
System.out.println("Element is matched in PDF is : " + text);
test.log(LogStatus.INFO, "Element is displayed in PDF " + text);
} else {
System.out.println("Element is not matched in PDF");
test.log(LogStatus.ERROR, "Element is not displayed in PDF :: " + text);
throw new AssertionError("Element is not displayed" + text);
}
} finally {
if (document != null) {
document.close();
}
fileToParse.close();
is.close();
}
return output;
}
关于java - 使用 Selenium JAVA 下载在新窗口中打开的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59486211/
我正在尝试使用特定路线打开一个新窗口,但似乎路线页面未正确加载。将从FrmApprovalMain.js打开新的 Electron 窗口,并应使用FrmPOdet.js打开新窗口。但是,当它打开时,会
我对 Tkinter 比较陌生,我需要帮助。 当从父窗口单击按钮时,我创建了一个新窗口。新窗口是 def new_Window。但我似乎无法获取窗口中的信息,如下编码: from tkinter im
我正在尝试使用 Javascript 从空白 iframe 中创建一个重定向,该 iframe 将定向到新窗口或选项卡中的 URL。 更具体地说,我试图让一个 Facebook 标签指向我公司的网页,
在问这个问题之前,我确实搜索了很多。抱歉,如果这是一个简单的问题。 在我的 wxWidgets 应用程序中,我想从菜单选项中新建一个 wxHtmlWindow。 (我已经正确显示了我的主应用程序窗口)
我认为我不是很了解这个,因为我对 jquery 还很陌生。我有一个隐藏了 3 个食谱的页面。单击食谱 A 的链接时,它会以模式打开。我希望能够只打印食谱的内容。所以我打开一个新窗口(非模态)并尝试将食
我想在带有可滚动文本框的现有主 Windwoe 旁边创建一个新窗口。 我在主窗口中按下“打开新窗口”按钮,然后它应该会打开一个带有可滚动文本框的新窗口。 在 form2 中 在 WPF 中,您可以在主
我正在使用 Simple Icons 制作自定义 Pinterest Pin It 按钮,我正在使用 Pinterest Widget Builder 给我的链接。在默认的 Pin It 按钮上,它会
我的表单上出现一个确认对话框,单击“确定”后会将用户重定向到另一个页面。 但是,是否可以在新窗口中打开该页面(例如 target="_blank") 我正在使用的代码是: var answer=con
相关但处于休眠状态:Javascript to open URL within a new Tab和其他一些...... 我有一个客户坚持认为特定链接需要在新选项卡中打开,而不是在窗口中打开。它由表单
我遇到了 Android 问题 WebView , 我想用 target='_blank' 打开一个 URL在同一WebView ,就像所有其他的一样URLs正在开放。 另请注意,我重写了 WebVi
可以从 Controller 重定向到某个 url 并同时在新窗口中打开该 url 吗? 最佳答案 不是真的来自 Controller Action 。 重定向是带有 301/302 状态代码和 Ra
在 Electron vue 中,我想为每个新窗口创建新的 vue 实例。这工作正常,直到我想将路由器子组件加载到新窗口。例如我有条目 add: path.join(__dirname, '../sr
案例1: var printWindow = window.open("", "print_window"); if(printWindow) { printWindow.addEventLi
我需要使用 Javascript Window.Open 函数打开一个新的 (_blank) 窗口。 URL 编码的回车符/换行符 (%0A) 似乎不起作用。有谁知道解决这个问题?例如,我有以下 UR
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Imp
当 flash 有键盘焦点时,CTRL+T(新标签)和 CTRL+N(新标签)窗口)被闪光拦截。 有没有办法将这些事件传递给浏览器以便它们工作(打开新选项卡,打开新浏览器)或者是否有用于这些操作的 j
我有一个 ASP.Net MVC 页面,上面有一个非常简单的表单:一个文本框和一个提交按钮。该表单使用标准的 mvc BeginForm() 语法: 当直接打开页面时,一切正常。 但是,我们有另一个
如果您对此问题感兴趣,请阅读下面的更新 #2 ;) 假设我将此代码放入我的扩展程序的 JS 中。 var reader = { onInputStreamReady : function(in
我是一名优秀的程序员,十分优秀!