RUVIDEO
Поделитесь видео 🙏

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

📁 Обучение 👁️ 17 📅 05.12.2023

WebElement interface all methods explained in detail with code examples
Like our facebook page www.facebook.com/ankprotraining

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.

Usage : driver.findElement(By.className("img-responsive")).isDisplayed();


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.

Usage : driver.findElement(By.id("Email")).isEnabled();

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

Usage : driver.findElement(By.id(“Email")).getLocation();

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.

Usage : driver.findElement(By.id("RememberMe")).isSelected();

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.

Usage :driver.findElement(By.id(“Email")).getSize();

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..

Usage : driver.findElement(By.id(“Email")).getTagName();

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.

Usage:driver.findElement(By.xpath(".//h2")).getText();

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.

Usage :driver.findElements(By.id(“Email”)).clear();

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.

Usage :driver.findElement(By.linkText(“Register”)).click();

Above code will click on the anchor tag which is having Register as link text.

findElement() method:
Locating element in IWebDriver is done by using the method “findElement(By.locator())”.
findElement() method takes locator(By object) as an argument and returns a object of WebElement.

Usage:driver.findElement(By.id("Email")).sendKeys("[email protected]");

Above code searches entire HTML document whose id is Email and sends keys [email protected] to that web element.

findElements() method:
FindElements() method takes locator(By object) as an argument and returns a collection of type IWebElement

Usage:driver.findElements(By.xpath("//input")).Count;

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

Usage : driver.findElement(By.tagName("img")).getAttribute("src");

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.

Usage : driver.findElement(By.id(“registerLink”)).getCssValue(“color”);

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.

Usage : driver.findElement(By.id(“Email”)).sendKeys(“[email protected]);

Above code searches entire HTML document whose id is Email and sends keys [email protected] to that web element.

submit() method:
This method used to submit HTML form into server, it can be used only when button type attribute is submit.

Usage : driver.findElement(By.xpath(".//input[@type='submit']")).submit();

Above code searches entire HTML document whose xpath is .//input[@type='submit'] and clicks on that button

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?

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Selenium with Java 15 - WebElement interface all methods explained in detail with code examples», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.