5

I have refreshed the browser in WebDriver using java as below code:

driver.navigate().refresh();

How can I do that by pressing Ctrl+F5 in WebDriver using Java?

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176

1 Answers1

8

I think you can use the WebDriver and Actions instance as below:

Actions actionObject = new Actions(driver);
actionObject.keyDown(Keys.CONTROL).sendKeys(Keys.F5).keyUp(Keys.CONTROL).perform‌​();
Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74
Ami
  • 4,241
  • 6
  • 41
  • 75
  • I ran the above code. Unfortunately, the following exception was occurred: java.lang.IllegalArgumentException: Key Down / Up events only make sense for modifier keys. – Ripon Al Wasim Sep 06 '12 at 13:03
  • Ctrl is a modifier key but F5 is not. You probably want to use actionObject.keyDown(Keys.CONTROL).sendKeys(Keys.F5).keyUp(Keys.CONTROL).perform(); – Ami Sep 06 '12 at 13:08
  • Thanks. The above code is helpful for me. "The method perform‌() is undefined for the type Actions" : this error was shown on above code. Small modified code is as below: actionObject.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform(); – Ripon Al Wasim Sep 06 '12 at 13:43