how to change file download location in Webdriver while using chrome driver/firefox driver

后端 未结 7 703
太阳男子
太阳男子 2020-11-30 07:42

I am trying to save an image by using save as option inside a specific folder. I found a way by which I am able to right click on the image which I want to save using save a

7条回答
  •  借酒劲吻你
    2020-11-30 08:12

    Use the same Robot class and press enter to select the "Save" in the Windows dialog box.

    robo.keyPress(KeyEvent.VK_ENTER); robo.keyRelease(KeyEvent.VK_ENTER);

    if you need to rename it copy the file name in the clipboard and pass like below

    StringSelection file = new StringSelection("D:\\image.jpg");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(file, null);
    
    Robot rb = new Robot();
    
    rb.setAutoDelay(2000); // Similar to thread.sleep
    
    rb.keyPress(KeyEvent.VK_CONTROL);
    rb.keyPress(KeyEvent.VK_V);
    
    rb.keyRelease(KeyEvent.VK_CONTROL);
    rb.keyRelease(KeyEvent.VK_V);
    
    rb.setAutoDelay(2000);
    
    rb.keyPress(KeyEvent.VK_ENTER);
    rb.keyRelease(KeyEvent.VK_ENTER);
    

提交回复
热议问题