3

Similar question asked below

How to save complete web page

But there is no answer yet. The expected result is to get many files, some file to store image, etc.

I used the following,it will pop up a windows saying to save the file

val a=new FirefoxDriver()
a.get("http://www.baidu.com")
val b=new Actions(a)
b.action.keyDown(Keys.ALT).keyDown(Keys.F4).keyUp(Keys.ALT).perform();

But then how to click the save button? The following doesn't work

b.sendKeys(Keys.ENTER)
Community
  • 1
  • 1
Daniel Wu
  • 5,853
  • 12
  • 42
  • 93

2 Answers2

8

We can use Robot utility in Java to handle this:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com/");

Robot robot = new Robot();

// press Ctrl+S the Robot's way
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_S);

Thread.sleep(2000L);

// press Enter
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

To use Robot utility you have to import following Java utilities:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Sitam Jana
  • 3,123
  • 2
  • 21
  • 40
-2

When you use Robot utility the x axis and y axis has to be metioned appropriately however it will differ system to system instead we can use AUTO IT. You can refer here http://www.autoitscript.com/forum/forum/9-example-scripts/

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
user2719138
  • 5
  • 1
  • 1
  • 4