How to Handle Browser in selenium

 : Handling Browser in selenium :


1- How to enter URL in browser using selenium webdriver ?

get() - In selenium webdriver , get method is used to open an URL .

Selenium Code :

//Enter URL in Browser

 driver.get("https://www.facebook.com/");


How to Navigate to URL or How to open a webpage in Selenium Browser?

navigate().to()- In selenium webdriver navigate to method is used to load a new webpage in the current browser window.

Selenium Code :

//Navigate to URL

 driver.navigat().to("https://www.facebook.com/");


How to Maximize browser window in selenium ?

maximize()- In selenium webdriver maximize method is used to maximize browser window.

Selenium Code:

//Maximize Browser Window 

 driver.manage().window().maximize();


How to refresh browser in selenium webdriver using java ?

In selenium there are multiple way to refresh browser .sometimes in certain browser normal refresh command does not work, in that situation we use these command to overcome from the situation.

1- refresh ()- Refresh command in selenium is most frequently used command by the IT professionals . Refresh command is a navigation command in selenium webdriver.

Selenium Code : 

//Refresh Browser Window

 driver.navigate().refresh();

2-sendkey ()- Sendkeys method in selenium is also used for refreshing a webpage. We use sendkeys method on any text box on webpage.

Selenium Code : 

//Refresh Browser Window

driver.get("https://www.facebook.com/"); 

driver.findElement(By.xpath("//input[@type='text']")).sendkeys(keys.F5);


How to click browser back button in selenium webdriver java ?

back() - Back method in selenium is used to click back button of an browser. Back command is a navigation command in selenium.

Selenium Code :

//Click browser Back Button

driver.get("https://www.facebook.com/");

 driver.navigate().back();


how to click browser forward button in selenium webdriver java ?

forward () - Forward method in selenium in used to click forward button of browser. Forward command is a navigation command in selenium webdriver .

Selenium Code :

//Click browser forward Button

driver.get("https://www.facebook.com/");

 driver.navigate().forward();


2- How to close browser window in selenium webdriver?

In selenium webdriver close () and quit () are two method to close the browser session . And knowing and understanding both of them is most important during the test execution .

1- close()- close method in selenium used to close the current browser window .

Selenium Code :

//Close Current browser window

      driver.close();

2-  quit ()- quit method in selenium is used to close all the open browser window and end the webdriver session .

Selenium Code :

//Close all browser window

      driver.quit();


Selenium code to automate browser window 


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
 
public class LaunchBrowser {
 
       public static void main(String[] args) {
              // TODO Auto-generated method stub
              System.setProperty("webdriver.chrome.driver", "C:\\Software\\chromedriver.exe");
              WebDriver driver=new ChromeDriver();
             
              //Maximize Browser Window
              driver.manage().window().maximize();
             
              //Enter URL in Browser
              driver.get("https://www.facebook.com/");

              
//Navigate to URL

                        driver.navigat().to("https://www.facebook.com/");

              //Refresh Browser Window
              driver.navigate().refresh();
             
              //Click browser Back Button
              driver.navigate().back();
             
              //Click Browser Forword button
              driver.navigate().forward();
             
              //Close Current brwoser window
              driver.close();
             
              //Close All open browser  window
              driver.quit();
      
       }
 
}



Handling Browser window in selenium


Post a Comment

0 Comments