Refresh is not working using sendkeys ,Selenium JAVA

driver.navigate().refresh ();
which command takes you forward by one page on the browser’s history?
what is the unit of movements string argument in drag and drop selenium action?
in webdriver ” selectalloptions() “ is a valid command.
which of the following method performs a context-click at the mouse location?
in webdriver, what is the return value of sendkeys function
which of the following clears all selected entries in selenium webdriver?
which is not a webelement method?

I am trying to automate google search,normal sendkeys is working ,but when I try to send using keys.F5 or ascii code ,refresh wont work also when try to do location reload it gives error as " The method execute_script(String) is undefined for the type WebDriver "

Tried instead of F5 ,F1 key also but no avail

   ` package com.at.sample;
import org.openqa.selenium.Keys;


import java.lang.Thread;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
// import org.openqa.selenium.Alert;
import java.util.List;





public class Refreshgoogle {
public static void main(String[] args) throws InterruptedException {

    WebDriver driver;
    System.setProperty("webdriver.chrome.driver","c://chromedriver.exe");
     driver= new ChromeDriver();

//Launch the Application Under Test (AUT)
driver.get("http://google.com");


Actions action = new Actions(driver);
WebElement element = driver.findElement(By.name("q"));

element.sendKeys("test data");
//sends normal keybaord strokes

 // approch 1  driver.findElement(By.xpath("//html")).sendKeys(Keys.F5);


// approch 2.1 WebElement element1 = driver.findElement(By.xpath("//*[@id=\"tsf\"]/div[2]/div[1]/div[2]/div[2]"));
//approch 2.2 element1.sendKeys(Keys.F1);


//  approch 3   driver.findElement(By.xpath("//*[@id=\"gsr\"]")).sendKeys(Keys.F5);

  // driver.execute_script("location.reload(true);");


System.out.println(driver.getTitle());
// working driver.navigate().to(driver.getCurrentUrl());


}
}
`

There are 4 approaches First 3 wont refresh pagea when used 4th it shows error as The method execute_script(String) is undefined for the type WebDriver

You can refresh in below ways:

1.Using get method and recursive way

    driver.get("https://URL.com");
    driver.get(driver.getCurrentURL());
  1. Using Navigate method and Recursively calling your URL

    driver.get("https://URL.com"); driver.navigate.to(driver.getCurrentURL());

  2. Using one valid webelement and send keys

    driver.get("https://URL.com"); driver. findElement(By.id("username")).sendKeys(Keys.F5);

Hope this help.

Refresh is not working using sendkeys ,Selenium JAVA – Onooks, I am trying to automate google search,normal sendkeys is working ,but when I try to send using keys.F5 or ascii code ,refresh wont work If you are working with Selenium and if SendKeys is not working in Selenium then you have to do small settings which will fix your issue. Please refer below screenshot for the exact problem statement.

Please refer below solution

driver.navigate.refresh();

If you want to refresh your page using keys then you can also use Robot class.

    Robot robot = new Robot();  // Robot class throws AWT Exception
    Thread.sleep(2000); // Thread.sleep throws InterruptedException
    robot.keyPress(KeyEvent.VK_CONTROL);  // press Control key down key of 
    robot.keyPress(KeyEvent.VK_F5);
    robot.keyRelease(KeyEvent.VK_CONTROL);  
    robot.keyRelease(KeyEvent.VK_F5);
    Thread.sleep(2000); 

This is selenium related issue more details available here: https://github.com/webdriverio/webdriverio/issues/1344

Refresh Page using Selenium Webdriver, Different ways to refresh browser with examples. or on certain pages, normal refresh command deos not work, in those situations we can As it is using a send keys method, we must use this on any Text box on a webpage. I am using this statement . driver.findElement(By.xpath("Element')]")).sendKeys(Keys.ARROW_DOWN); But when I run it, I couldn't see any movement in the page. I am using JAVA to automate. This issue occurs even in BEHAT\MINK Tool. My doubt: is this feature not working because of the developers code? or I need to modify my code to make it work?

WebElement(I) sendKeys() will not accept Keys (keyboard keys). This can be handled using Actions class only.

Additionally, if you need to refresh the page, use WebDriver() refresh() or get current URL using getCurrentUrl() of same interface and navigate() using same url as parameter.

Update:

Here is the detailed explanation on each approach: 1) As per 'https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html#sendKeys-java.lang.CharSequence...-', sendKeys() in WebElement(I) accepts only char sequence (i.e. string.). // approch 1 driver.findElement(By.xpath("//html")) returns a WebElement and this element sendKeys will accept only char sequence. Hence, your approach r=to refresh using Keys.F5 won't work here.

2) // approch 2.1 WebElement element1 = driver.findElement(By.xpath("//*[@id=\"tsf\"]/div[2]/div[1]/div[2]/div[2]")); //approch 2.2 element1.sendKeys(Keys.F1); Same explanation as approach 1.

3) // approch 3 driver.findElement(By.xpath("//*[@id=\"gsr\"]")).sendKeys(Keys.F5); Did the same kind of operation as approach 1 and is explained there.

4) If we need to use javascriptexecutor, first we need to create javascriptexecutor object like below and should call execute_script() using reference variable of that object:

JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript(Script,Arguments);

If you are not created this object, you will get 'execute_script(String) is undefined for the type WebDriver', which is expected.

Hence, the 4 approaches what you tried will not refresh the page. Instead, you can use below options:

1) Actions class sendKeys(): which will accept keyboard keys. 2) using driver.navigate().refresh(); 3) Using javascriptexecutor after creating an object for the same (as explained in approach 4)

Try with this code:

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import io.github.bonigarcia.wdm.WebDriverManager;

public class TestRefresh {

    public static void main(String[] args) {

        WebDriverManager.chromedriver().setup();

        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.com");
`//     case 1:`
        `driver.navigate().to(driver.getCurrentUrl());`
`//     case 2:`
        `((JavascriptExecutor)driver).executeScript("document.location.reload()");`
`//     case 3:`
        `driver.navigate().refresh();`
    }

}

Refresh Browser in Different Ways in Selenium WebDriver, Different ways to reload a page in selenium webdriver with java. driver.​findElement(By textboxLocator).sendKeys(Keys.F5);  sendKeys() not working in Selenium Webdriver +2 votes I was trying to send keys to a text box and send a tab key both at the same time to check for the availabilty of the username

How to refresh or reload a webpage in Selenium Webdriver wth java?, Working with browser navigation Browsers provide various navigation methods to by refreshing the current page with the back, forward, and refresh/reload buttons on the The Selenium WebDriver API provides access to these buttons with various and checks the behavior of the application in following code example:  On the initial page load, some web elements might be loaded while it takes a second page refresh for all web elements to be loaded. This can be done using the refresh command provided by Selenium web driver. Browser refresh operation can be performed using the following ways in Selenium.

5 different ways to refresh a webpage using Selenium Webdriver, Bug Report Not able to press Ctrl + F5 keys to do hard refresh using chromedriver and C# webdriver bindings To Reproduce On any page, try to do GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. SendKeys(element. Click OK according to Selenium Webdriver Ok so I know there are a number of other answers on this question about alerts in webdriver and I've looked through them but I think my situation is a little different.

Selenium Testing Tools Cookbook, We can refresh a web page in many ways in Selenium Webdriver. Problem with Actions class is that it may work or may not depending on browser and driver.findElement(By.tagName("a")).sendKeys(Keys.chord(Keys. driver.findElement(By.name("Email")).sendKeys("automation@gmail.com"); This should work to insert values/text into Text-box input field. If not working pls cross-check below points: Screen/Page is loaded completely; Assert that textbox is enabled and visible; If you found any of above points failing, you should try: WaitForElement(your_element

Comments
  • try with driver.navigate.refresh(); Is there any specific reason you wanna use sendkeys?
  • You send keys to element, not to browser or operating system
  • @Pratik I am just learning phase,want to try all methods
  • I said I want to use sendkeys
  • thats issue I mentioned in title
  • refresh using other method working,I mainly want using sendkey for learning purpose which is not working ,sending alphabet also working,but ascii or F5 key its not refreshing
  • its nice answer now,so whats trick for using sendkeys and F5 ,which element accept this command?
  • If you need to refresh using F5 option, then preferred to go with 'Actions' class sendKeys().
  • is there I use on page? i.e. selecting any other thing than web element
  • To refresh the page using Actions class, we do not need WebElement and your code should be like below: Actions actions = new Actions(driver); actions.sendKeys(Keys.F5);