WebElement Commands in Kotlin Selenium

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. WebElement interface is used to interact with both visible and invisible elements present on a page. So you should make that the element you are trying to access on the web page.

SendKeys() function:

sendKeys() sets a value into an element (editable input fields and dropdowns fields). This method accepts CharSequence as a parameter and returns nothing. CharSequence is top most interface for text values.


// set value in  WebElement
driver.findElement(By.id("locator")).sendKeys("some value")

Clear() function:

clear() will remove the value from the editable input fields like Textbar and text area, clear() function accepts nothing as a parameter and returns nothing.


// Clear  WebElement
driver.findElement(By.id("id of element")).clear()

Click() function:

Click() function is used to click any element, Accepts nothing as a parameter and returns nothing(type nothing).


// Click WebElement
driver.findElement(By.id("locator")).click()

text property:

text property will fetch the visible inner Text of the element, not only brings target element text but also brings the text from the inner elements of the target element.


// Get text of Particular WebElement & Store into String
    driver.findElement(By.id("locator")).text

tagName property :

tagName property gets the tag name of the Web Element. The tag name is nothing but the html tag which is used to build this element on the UI.


 // fetches the tag name
    driver.findElement(By.id("locator")).tagName

getAttribute function():

getAttribute(String Name) function gets the value of the given attribute of the element. Common attributes are like class, id, name, src, href. You can fetch any attribute fro the webelement


    driver.findElement(By.id("locator")).getAttribute("any attribute")

getCssValue functions():

getCssvalue( ) function fetches CSS property value of the give element. CSS properties are used for decorating the web element, for Example, font-size, corlor, background-color, padding so on.


driver.findElement(By.id("locator")).getCssvalue("any css property")

Size property:

size property fetches the width and height of the target element, returns the Dimension object. This returns the size of the element on the page.


val ele = driver.findElement(By.id("locator"))
val dimensions = ele.size
println("Height :" + dimensions.height + "Width : " + dimensions.width)

location property:

location property returns the location of the element on the page. getLocation returns the Point object, from which we can get X and Y coordinates of specific element.


val elementLocation = driver.findElement(By.id("locator"))

val point = elementLocation.location

println("X cordinate : " + point.x + "Y cordinate: " + point.y)

Submit() function:

submit( ) function submits a form, you should use this function only on elements which are present inside the <form> tag in html


driver.findElement(By.id("locator")).submit()

isDisplayed property:

isDisplayed property is used to check if an element is currently being displayed or not on the webpage, this methods returns true if the element is displayed otherwise false.


// Verify WebElement is Present or Not?
    driver.findElement(By.id("locator")).isDisplayed

isEnabled property:

isEnabled property determines if the element currently is Enabled or not?, this methods returns true if the element is enabled otherwise false.


    // Verify WebElement is Enabled or Not
    driver.findElement(By.id("locator")).isEnabled

isSelected property:

isSelected property checks whether the element is selected or not. This property can be applied on checkboxes and radio button an dropdowns as well. isSelected() return true if the element is selected otherwise false.


// Verify WebElement is Selected or Not
driver.findElement(By.id("locator")).isSelected

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
You can also share knowledge by Adding a topic here


Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Selenium Online Training : Our next online training course for Selenium with Java starts from 17th December 2018.

You can attend first 3 classes for free, the total course fee is INR 10,000

The course time would be 8.00 PM(IST) for the first three classes

If you are interested to learn, then you can join the course by sending email to chercher.tech@gmail.com

or Register below


 
Join My Facebook Group
Join Group