Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Selenium Webdriver: Refresh the browser

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.46k
    Comment on it

    Sometimes you need to refresh the current page of the web application. In Selenium Webdriver you can perform this operation by multiple ways.


    There are following ways to refresh or reload the browser or the application.

     

    1. Using refresh method:- This is most common method in webdriver to perform this task.

    Syntax:-

    driver.navigate().refresh();

    Sample code:-

    driver.get("http://findnerd.com/NerdDigest");
     
    driver.navigate().refresh();


    2. Using sendkeys() method:- Its a second most commonly used method in selenium to refresh  a webpage. Its like manually pressing the F5 key on keyboard.

    Syntax:-

    driver.findElement(By.id(locator)).sendKeys(F5 key);
    or
    driver.findElement(By.name(locator)).sendKeys(F5 key);

    Sample code:-

    driver.get("http://findnerd.com/NerdDigest");
     
    // Element "q" is a Seach Text box on my website
     
    driver.findElement(By.id("q")).sendKeys(Keys.F5);

    3.Using navigate().to() command:- In this method you feed the same URL using navigate().to() method or feeding with a current page url and an argument.

    Syntax:-

    driver.navigate().to(driver.getCurrentUrl());

    Sample code:-

    driver.get("http://findnerd.com/NerdDigest");
     
    driver.navigate().to(driver.getCurrentUrl());


    4.Using get() command:- It is just like feeding page URL as a argument with get command .for this you should  know the URL of page.

    You can also use get function to get the current page URL.

    Syntax:-

    driver.get("URL of the page");

    driver.get(driver.getCurrentUrl());

    Sample code:-

    driver.get("http://findnerd.com/NerdDigest");
     
    driver.get(driver.getCurrentUrl());


    5. sendkeys() method with ASCII code:- Its equivalent to f5 key command of keyboard: In this you use ASCII code as an argument on sendkeys() method.


    Syntax:-

    driver.findElement(By.id("ELEMENT ID")).sendKeys("ASCII CODE");

    Sample code:

    driver.get("http://findnerd.com/NerdDigest");
    driver.findElement(By.id("q")).sendKeys("\uE035");


    6.Using executeScript() command:- By this you can execute any java script command. if you execute location.reload() function it will reload your current page.

    Syntax:-

    driver.executeScript("location.reload()");

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: