需要通过点击网址中的下载链接来捕获我们获得的PDF文件名。我已尝试使用此代码。但是,我无法从第二个窗口获取标题或网址 请帮我解决这个问题,或建议我采用其他任何方法来解决这个问题......
**code I tried**
@Test
public void pdfname() throws Exception {
driver.get(baseUrl + "/english/investments/iv_funds.htm");
Set<String> winids = driver.getWindowHandles();
Iterator<String> iterate = winids.iterator();
Thread.sleep(3000);
driver.findElement(By.linkText("FUND MATERIALS")).click();
Thread.sleep(3000);
driver.findElement(By.className("sbToggle")).click();
Thread.sleep(3000);
driver.findElement(By.linkText("Fund Details and Performance Update")).click();
driver.findElement(By.id("fundPerformance")).click();
driver.findElement(By.id("fundPerformance")).clear();
driver.findElement(By.id("fundPerformance")).sendKeys("AEGAU");
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@id='perform']")).click();
Thread.sleep(18000);
winids = driver.getWindowHandles();
iterate = winids.iterator();
String firstwindow=iterate.next();
String secondwindow = iterate.next();
System.out.println(firstwindow);
System.out.println(secondwindow);
driver.switchTo().window(secondwindow); //switch to pdf window
Thread.sleep(3000);
System.out.println("url is"+driver.getCurrentUrl());
driver.close();
}
答案 0 :(得分:0)
我认为您正试图从OS系统窗口获取该名称。 Selenium不与OS交互。对于Windows,您可以使用autoit(http://www.autoitscript.com/site/autoit/)与操作系统进行交互。