2

This might be the thousand question about the same topic, and I'm sorry for that. Others answers are not updated because most of them are old now, others simply are for other languages.

I'm trying to download a file, which is generated by compiling a html form. So this following code would fill everything needed in the form, eventually clicking on Submit:

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();
}

I do not expect it to be as simple as submit(); and adding the local-storage-path capability, which I hoped was all it needed but it actually does not save anything.. So I'm asking you, if someone knows or have a piece of code, in Java, that is able to manage this kind of downloads.

Thank you!

aPugLife
  • 989
  • 2
  • 14
  • 25
  • My other question have a working answer, using chromedriver: https://stackoverflow.com/questions/44721679/downloading-a-file-from-selenium-and-chromedriver – aPugLife May 03 '18 at 07:52

0 Answers0