此代码是以虚拟形式下载pdf文件但不下载,任何人都可以帮助我...
我需要为下载文件提供downloadfilepath。
package core;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Phantom {
public static void main(String[] args) throws InterruptedException {
Capabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
((DesiredCapabilities) caps).setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
new String[] {"--ssl-protocol=tlsv1"});
((DesiredCapabilities) caps).setCapability("phantomjs.binary.path","..../phantomjs-2.1.1-linux-x86_64/bin/phantomjs");
String[] phantomArgs = new String[] {
"--webdriver-loglevel=NONE"
};
((DesiredCapabilities) caps).setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
WebDriver driver = new PhantomJSDriver(caps);
//Sample site to download the pdf file
driver.get("https://www.researchgate.net/publication/265262543_HTML_Web_Design_in_7_days");
Thread.sleep(10000);
System.out.println("Page title is: " + driver.getTitle());
System.out.println("Page url is: " + driver.getCurrentUrl());
driver.findElement(By.xpath("//a[@class='blue-link js-download btn btn-large btn-promote']")).click(); //Click on the link to download
// After the above click, file should download but it doesn't not happens
driver.quit();
}
}