【发布时间】:2018-06-07 18:20:20
【问题描述】:
我正在尝试通过将内容复制到剪贴板并传输到字符串来验证 pdf 的内容。下面是我的代码
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
for (String string : tabs) {
System.out.println("tab id:: "+string);
}
driver.switchTo().window(tabs.get(1)); //pdf opens in new tab so switching to new tab
pause(5000);
String selectAll = Keys.chord(Keys.CONTROL,Keys.chord("a"));
String copy = Keys.chord(Keys.CONTROL,Keys.chord("c"));
driver.switchTo().frame(driver.findElement(By.xpath("//html/body//div/div/iframe")));
driver.findElement(By.xpath("//*[@id='plugin']")).sendKeys(selectAll); //Select all works on the opened pdf
pause(3000);
driver.findElement(By.xpath("//*[@id='plugin']")).sendKeys(copy);
pause(5000);
Clipboard clipboard2 = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard2.getContents(null);
String x = (String) contents.getTransferData(DataFlavor.stringFlavor);
System.out.println(x); //getting worng out put here instead of pdf content
选择内容有效,但我得到一些像这样的随机输出
tab id:: CDwindow-FC2070E3D2902357E08E5D6720AF9766
tab id:: CDwindow-D06392BD9261B14C083395D57AE805FA
Clipboard clipboard2 = Toolkit.getDefaultToolkit().getSystemClipboard();
不知道我做错了什么。 任何人都可以帮忙。 谢谢。
Chomredriver 2.39 Chrome 版本 66
【问题讨论】:
标签: java selenium pdf automation clipboard