Java 使用Selenium和PhantomJS下载从表单生成的文件
这可能是关于同一主题的一千个问题,对此我很抱歉。其他答案没有更新,因为现在大多数答案都是旧的,其他答案只是针对其他语言 我正在尝试下载一个文件,它是通过编译html表单生成的。 因此,以下代码将填写表单中所需的所有内容,最后单击Submit:Java 使用Selenium和PhantomJS下载从表单生成的文件,java,selenium,download,phantomjs,Java,Selenium,Download,Phantomjs,这可能是关于同一主题的一千个问题,对此我很抱歉。其他答案没有更新,因为现在大多数答案都是旧的,其他答案只是针对其他语言 我正在尝试下载一个文件,它是通过编译html表单生成的。 因此,以下代码将填写表单中所需的所有内容,最后单击Submit: public void UsingPhantomjs() throws IOException{ DesiredCapabilities cap = DesiredCapabilities.phantomjs(); cap.setCapa
public void UsingPhantomjs() throws IOException{
DesiredCapabilities cap = DesiredCapabilities.phantomjs();
cap.setCapability("phantomjs.binary.path","src\\main\\resources\\driver\\phantomjs.exe");
cap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--ignore-ssl-errors=true", "--local-storage-path=C:\\"});
PhantomJSDriver driver = new PhantomJSDriver(cap);
driver.get("https://this-website/thispage");
WebElement select1 = driver.findElementByName("list1");
Select field1 = new Select(select1);
field1.selectByIndex(1);
WebElement select2 = driver.findElementByName("list2");
Select field2 = new Select(select2);
field2.selectByIndex(1);
driver.findElement(By.id("id1")).sendKeys("26/06/2017");
driver.findElement(By.id("id2")).sendKeys("27/06/2017");
driver.findElement(By.id("id3-1")).click();
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("C:\\screenshot.png"));
driver.findElement(By.id("id5")).submit();
driver.quit();
}
我不希望它像提交一样简单;并添加了本地存储路径功能,我希望这是它所需要的全部功能,但实际上并没有保存任何内容。。所以我想问你,如果有人知道或者有一段Java代码,能够管理这种下载
谢谢大家! 我的另一个问题有一个有效的答案,使用chromedriver: