filmov
tv
Selenium with Java 15 - WebElement interface all methods explained in detail with code examples

Показать описание
WebElement interface all methods explained in detail with code examples
What is WebElement interface?
All elements present in html document is a WebElement.
HTML elements like text box, button, checkbox, div, span etc.. are web elements
WebElement is an interface
WebElement contains methods for web elements
findElement and findElements methods will return WebElement object and objects respectively
isDisplayed() method:
This method is used to verify whether element is available in UI.
It will return boolean true value if object is available in UI.
Above code will return true whether the element having class name is img-responsive is displayed.
isEnabled() method:
This method is used for verify whether element is active in UI.
It will return boolean true value if object is active in UI.
Above code will return true whether the element having id Email is enabled.
getLocation() method:
This method is used to capture the location of the selected web element.
It will return the point containing the location of the top left-hand corner of the element
Above code will return X and Y co-ordinates from top left corner for element having id Email.
isSelected() method:
This method is used for verify weather radio button, checkbox or dropdown are already selected or not.
It will return boolean true value if object is selected already.
Above code will return true if the element having RememberMe is selected.
getSize() method:
This method will gets the height and width of the selected web element.
It will return Dimension, this Dimension can capture height and width coordinates of the element.
Above code will return height and width of the element whose name is username.
getTagName() method :
This method is used to capture the tag name of element..
Above code will return TagName of the webelement whose Id is Email.
getText() method:
This method is used to capture the text from the identified element.
Above code will return the text present within h2 tag.
clear() method:
This method is used to reset existing value from textbox or textarea box.
Above code will clear the text present in web element whose id is email.
click() method:
This is used to perform left click operation on the selected web element.
Above code will click on the anchor tag which is having Register as link text.
findElement() method:
findElement() method takes locator(By object) as an argument and returns a object of WebElement.
findElements() method:
FindElements() method takes locator(By object) as an argument and returns a collection of type IWebElement
Above code searches entire HTML document whose tag name is input and returns a count of the such web elements.
getAttribute() method:
This method used to get the value of the passed attribute for selected web element
Above code will return the value of the src attribute of the element having img as tagname.
getCssValue() method:
This method used to get the value of the passed css property for selected web element.
Above code will return the color css property value of the element having registerLink as Id.
sendKeys() method:
This method used to pass or type data into text box or text area box.
submit() method:
This method used to submit HTML form into server, it can be used only when button type attribute is submit.
Possible Interview Questions on WebElement interface:
What is WebElement interface?
What are the different types of methods available in WebElement interface?
What is the difference between findElement and findElements?
What is WebElement interface?
All elements present in html document is a WebElement.
HTML elements like text box, button, checkbox, div, span etc.. are web elements
WebElement is an interface
WebElement contains methods for web elements
findElement and findElements methods will return WebElement object and objects respectively
isDisplayed() method:
This method is used to verify whether element is available in UI.
It will return boolean true value if object is available in UI.
Above code will return true whether the element having class name is img-responsive is displayed.
isEnabled() method:
This method is used for verify whether element is active in UI.
It will return boolean true value if object is active in UI.
Above code will return true whether the element having id Email is enabled.
getLocation() method:
This method is used to capture the location of the selected web element.
It will return the point containing the location of the top left-hand corner of the element
Above code will return X and Y co-ordinates from top left corner for element having id Email.
isSelected() method:
This method is used for verify weather radio button, checkbox or dropdown are already selected or not.
It will return boolean true value if object is selected already.
Above code will return true if the element having RememberMe is selected.
getSize() method:
This method will gets the height and width of the selected web element.
It will return Dimension, this Dimension can capture height and width coordinates of the element.
Above code will return height and width of the element whose name is username.
getTagName() method :
This method is used to capture the tag name of element..
Above code will return TagName of the webelement whose Id is Email.
getText() method:
This method is used to capture the text from the identified element.
Above code will return the text present within h2 tag.
clear() method:
This method is used to reset existing value from textbox or textarea box.
Above code will clear the text present in web element whose id is email.
click() method:
This is used to perform left click operation on the selected web element.
Above code will click on the anchor tag which is having Register as link text.
findElement() method:
findElement() method takes locator(By object) as an argument and returns a object of WebElement.
findElements() method:
FindElements() method takes locator(By object) as an argument and returns a collection of type IWebElement
Above code searches entire HTML document whose tag name is input and returns a count of the such web elements.
getAttribute() method:
This method used to get the value of the passed attribute for selected web element
Above code will return the value of the src attribute of the element having img as tagname.
getCssValue() method:
This method used to get the value of the passed css property for selected web element.
Above code will return the color css property value of the element having registerLink as Id.
sendKeys() method:
This method used to pass or type data into text box or text area box.
submit() method:
This method used to submit HTML form into server, it can be used only when button type attribute is submit.
Possible Interview Questions on WebElement interface:
What is WebElement interface?
What are the different types of methods available in WebElement interface?
What is the difference between findElement and findElements?
Комментарии