WebElement Commands in selenium :

 

What is WebElement ?

  • WebElement is an object / HTML element.
  • HTML elements can be written with a start tag, end tag, with the content in between: <tagname> Web Page content </tagname>
  • HTML heading for Web Page <h1> Heading </h1>
  • The HTML element is everything from the start tag to the end tag: <p> paragraph </p>

 

WebElement Syntax :

 

Demo HTML Code :

 

  • WebElement commands in selenium will be applicable to almost all the DOM elements on the web page.
  • Every single controls present on the page is called a WebElement in WebPage.
  • Each of WebElement is represented in selenium by WebElement interface.
  • Note:  WebElement interface is used to interact with both visible and invisible elements present on a page.

 

 

Clear Command:

  • clear( ) : If element is a text entry element, this will clear the value.
  • This method accepts nothing as a parameter and returns nothing.
  • This method has no effect on other elements, except text elements.
  • Text entry elements and TextArea elements are INPUT.

 

SendKeys Command:

  • sendKeys(“Text” ) : This simulate typing into an element, which may set its value. This method accepts Char Sequence as a parameter and returns nothing.
  • This method works fine with text entry elements like INPUT and Text Area elements.

 

Click Command:

  • click( ) : This command use to clicking of any element. Accepts nothing as a parameter and returns nothing.
  • Clicking is the most common way of interacting with web elements like text elements, links, radio boxes and many more.

 

isDisplayed Command:

  • isDisplayed( ) : This commad is used to check if an element is currently being displayed or not. This accepts nothing as a parameter but returns boolean value(true/false).
  • This will return true if the element is present on the page and throw a NoSuchElementFound exception if the element is not present on the page.

 

isEnabled Command:

  • isEnabled( ) : This determines if the element currently is Enabled or not? This accepts nothing as a parameter but returns boolean value(true/false).

 

isSelected Command:

  • isSelected( ) : Determine whether or not this element is selected or not.
  • This accepts nothing as a parameter but returns boolean value(true/false).
  • This operation only applies to input elements such as Checkboxes, Select Options and Radio Buttons.
  • This returns True if the element is currently selected or checked, false otherwise.

 

Submit Command:

  • submit( ) : This method works well / better than the click() if the current element is a form, or an element within a form.
  • This accepts nothing as a parameter and returns nothing in WebElement commands in selenium.
  • If this causes the current page to change, then this method will wait until the new page is loaded.

 

GetText Command:

  • getText( ) : This method will fetch the visible inner Text of the element.
  • This accepts nothing as a parameter but returns a String value.

 

getTagName Command:

  • getTagName( ) : This method gets the tag name of the Web Element. This accepts nothing as a parameter and returns a String value.

 

getAttribute Command:

  • getAttribute(String Name) : This method gets the value of the given attribute of the element.
  • This accepts the String as a parameter and returns a String value.

 

getCssValue Command:

  • getCssvalue( ) : This method Fetch CSS property value of the give element.
  • This accepts nothing as a parameter and returns a String value.

 

getSize Command:

  • getSize( ) : This method fetch the width and height of the rendered element.
  • This accepts nothing as a parameter but returns the Dimension object.
  • This returns the size of the element on the page.

 

getLocation Command:

  • getLocation( ) : This method locate the location of the element on the page. This accepts nothing as a parameter but returns the Point object.
  • This returns the Point object, from which we can get X and Y coordinates of specific element.

 

Example of WebElement Commands:

WebElement Commands in selenium and WebElement Commands in selenium test WebElement Commands in selenium and selenium commands