Thursday 9 February 2017

Selenium WebDriver Commands:



Selenium WebDriver Commands:


1.get(String):
method Load a new web page in the current browser window. Accepts String as a parameter and returns nothing.

Syntax: public void get(String url)
Example: driver.get("http://www.google.com"); 

2.getTitle():
This method fetches the Title of the current page. Accepts nothing as a parameter and returns a String value.

syntax: public String getTitle()
Example: String title=driver.getTitle();

3. getCurrentUrl():
This method fetches the string representing the Current URL which is opened in the browser. Accepts nothing as a parameter and returns a String value.
Syntax: public String getCurrentUrl()
Example: String currentUrl= driver.getCurrentUrl();


4. getPageSource():
This method returns the Source Code of the page. Accepts nothing as a parameter and returns a String value.
syntax: public String  getPageSource()
Example: String title=driver. getPageSource ();

5. close():
This method Close only the current window the WebDriver is currently controlling. Accepts nothing as a parameter and returns nothing.

syntax:public void close()

Example: driver.close();

6. quit():
This method Closes all windows opened by the WebDriver. Accepts nothing as a parameter and returns nothing. Close every associated window.

synatx: public void quit()

Example: – driver.quit();

7. findElement()
This method finds the element within the current page using ElementLocator(id,name,xpath....etc)
Syntax: public WebElement findElement(By arg0)
Example:
driver.findElement(By.id("passwd-id")); Finding Element using Id

driver.findElement(By.name("passwd")); 
Finding Element using Name

driver.findElement(By.xpath("//input[@id=’passwd-id’]")); 
Finding Element using Xpath



8.findElements():
Whenever we call findElements() it is going to identify all the corresponding webelemets in the form of list using ElementLocator(id,name,xpath....etc)

Syntax: public List<WebElement>  findElements(By arg0);
Example:
 List<WebElement> elements=driver.findElement(By.id("passwd-id")); Finding Elements using Id

List<WebElement> elements=driver.findElement(By.name("passwd-id")); Finding Elements using name

9.sendKeys():
By using this method ,we can pass the text data  to the WebElements on WebElement only we need to call this method.
Syntax: public void sendKeys(String text)
Example:  driver.findElement(By.id("passwd-id")).sendKeys("123456");

10.getWindowHandle():
Whenever we cal this method ,it will return current focused window name in the form of  String
Syntax: public  String  getWindowHandle()
Example: String  window=driver.getWindowHandle();
11.getWindowHandles():
Whenever we cal this method ,it will return all the window names in the form of Set of Strings
Syntax: public Set<String>  getWindowHandles()
Example: Set<String> windows=driver.getWindowHandles();
12.manage():
By using manage() ,we can perform managing operations like maximizing the window,time initializations and perfroming operations on keys.
Syntax: public void manage()
Example:
driver.manage().deleteAllCookies();
driver.manage().window().maximize();

13.navigate():
If we want to perform navigation operations we can use navigate().and also we can perform navigations like refresh,back,froward...etc.
Syntax: public void navigate()
Exmple: 
driver.navigate().To("https://www.gmail.com");
driver.navigate().back();
driver.navigate().forward();

14.switchTo():
By using this method ,we can switch to windows,frames,alerts...etc
syntax: public TargetLocator  switchTo();
Example:
driver.switchTo().alert();
driver.switcho().frame(-);
driver.switchTo.window(-);

15.clear()
This method is used to clear the text feild.
syntax: public void clear()
Example: 
driver.findElement(By.id("passwd-id")).clear();
driver.findElement(By.id("passwd-id")).sendKeys("123456");

16.click():
By using this method ,we can perform clickable operations on webelemets.
Syntax: public void   click()
Example: 
WebElemet ele=driver.findElement(By.id("next"));
ele.click();

17. isSelected():
This method determines if an element is selected or not. It returns true if the element is selected and false if it is not.  It is widely used on check boxes, radio buttons and options in a select.
Syntax: public boolean isSelected()
Example: driver.findElement(By.id("check")).isSelected();

18. isDisplayed():
This method determines  if an element is displayed or not. It returns true if the element is displayed and false if it is not. Advantage of this method is that it avoids parsing an elements style attribute.

Syntax: public boolean isDisplayed()
Example:driver.findElement(By.id("check")).isDisplayed();

19.isEnabled():
This method determines if an element is enabled or not. It returns true if element is enabled and false if otherwise.
Syntax: public boolean  isEnabled()
Example: driver.findElement(By.id("check")).isEnabled();

No comments:

Post a Comment