Purpose: Its Opens Specified Url in the Browser Window
//Launch Browser
System.setProperty(“webdriver.chrome.driver”,”D:\\Onlineqaclasses\\chromedriver_win32\\chromedriver.exe”);
//ChromeDriver driver=new ChromeDriver();
System.setProperty(“webdriver.ie.driver”,”D:\\Onlineqaclasses\\IEDriverServer_Win32_2.53.0\\IEDriverServer.exe”);
InternetExplorerDriver driver=new InternetExplorerDriver();
//Using get()
driver.get(“http://www.onlineqaclasses.com”);
Purpose: Its Returns title of the Browser
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://www.onlineqaclasses.com”);
//Using getCurrentUrl()
String url=driver.getCurrentUrl();
System.out.println(“Current page url is—> “+url);
Purpose: Gets the title of the current web page.
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://www.onlineqaclasses.com”);
//Using getCurrentUrl()
String title=driver.getTitle();
Purpose: Get the source of the currently loaded page.
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://www.onlineqaclasses.com”);
//Using getPageSource()
String pagesource=driver.getPageSource();
System.out.println(pagesource);
Purpose: Find the first WebElement using the given method.
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://www.onlineqaclasses.com”);
//Using findElement()
WebElement gmaillink=driver.findElement(By.className(“gb_P”));
//Getting name of link
System.out.println(“result element name :”+gmaillink.getText());
Purpose: Find all elements within the current page using the given mechanism.
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://www.onlineqaclasses.com”);
//Using findElements()
List<WebElement> links=driver.findElements(By.TagName(“a”));
//Counting no of links in result page
System.out.println(“Number of Links in current page :”+links.size());
Purpose: Close the current window, if there are multiple windows, it will close the current window which is active and quits the browser if it’s the last window opened currently.
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://www.onlineqaclasses.com”);
//Using close()
driver.close();
Purpose: Quits this driver instance, closing every associated window which is opened.
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://www.onlineqaclasses.com”);
//Using quit()
driver.quit();
getWindowHandle()
Purpose: Whenever the web driver launches the browser it assigns the unique id to that browser which is called as window handler. This can be captured through the method.
Syntax: driver.getWindowhandle()
Purpose:: Whenever multiple windows are opened by webdriver and we want to capture all their ids. We use this method.
Syntax: getWindowHandles()
switchTo():-
Purpose:used to switch from one window to another window (or) window to a frame (or) frame to a window (or) window to an alert
Syntax: driver.switchTo().window();
driver.switchTo().frame();
driver.switchTo().alert();
navigate()
Purpose: An abstraction allowing the driver to access the browser’s history and to navigate to a given URL.&Refresh page
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://gmail.com”);
//navigate to page
driver.navigate().to(“http://onlineqaclasses.com “);
//navigate to back
driver.navigate().back();
//navigate to forward
driver.navigate().forward();
//navigate to refresh page
driver.navigate().refresh();
manage()
Purpose: This is used to perform various activities like maximize the size of the window, Cpture the information about the cookies, setting implicit wait etc.
//Launch Browser
FirefoxDriver driver=new FirefoxDriver();
//Using get()
driver.get(“http://gmail.com”);
//to maximize window
driver.manage().window().maximize();
© Copyright 2016-2018 Onlineqaclasses
Onlineqaclasses
Leave a Reply