SELENIUM BASICS:


SELENIUM WEBDRIVER:


TESTNG:


REPORTS:


BUILD & CONTINUOUS INTEGRATION TOOLS:


CROSS BROWSER TESTING:


MOBILE TESTING:


AUTOMATION FRAMEWORKS:


API Testing:


INTERVIEW QUESTIONS:


SAMPLE RESUME:

Webelement commands in Selenium Python

In the previous articles on Selenium Python Tutorial, we have covered “Synchronization in Selenium Python“. In this tutorial, we will learn Webelement commands in Selenium Python.

Let us discuss some of the common Webelement commands used in Selenium Python. With the help of the web element commands, we can successfully perform actions on elements and also validate its behavior and other characteristics.

What is WebElement?

WebElement in Selenium represents an HTML element. It basically represents a DOM element in a HTML document.

WebElement Commands in Selenium Python

The following are some of the most commonly used WebElement commands in Selenium WebDriver.

send_keys ()

This is a method that is used to input text in an edit box, text area, fields inside the form, and so on. This method can also be used for setting up file inputs and to send modifier keys from the Keys class.

click ()

This is a method that is used to click on a link or button. The element to be clicked is specified in the parameter of the method. If no parameter is mentioned, the present mouse position is clicked.

InvalidElementException is thrown if we try to click on an element in a disabled state.

Code Implementation with click () method.

clear ()

This is a method that is used to clear the text from an edit box or a text area. Once the existing text is cleared, send_keys () method is applied to again input our desired text. Code Implementation with a clear () method.

submit ()

This is a method that can be used with any element within the form tag. It waits to complete the page load and submit the form. Code Implementation with submit () method.

text

This is used to fetch the inner text of an element. It mainly takes care of the text displayed on the screen with its sub-elements without considering the leading and trailing spaces. Code Implementation with text.

get_attribute ()

This method is used to get the attribute or property value of an element. This method identifies the key-value pair in an HTML document. If a value is not set for an attribute in the HTML document, none is retrieved by the method. In case an attribute value is in Boolean, the get_attribute () method gives true or false. The attribute which we want to fetch is passed as an argument to the method. Code Implementation with get_attribute ().

value_of_css_property ()

This method is used to get the value of the CSS property of the element. The method accepts the name of the CSS property for which we want to get the value. Code Implementation with value_of_css_property ().

is_displayed ()

This method is used to check if the web element is displayed on the page or not. This method gives a Boolean value of either true or false. Sometimes an element contains an attribute as hidden. In that case, Selenium considers that element is not visible on the page and returns false. Code Implementation with is_displayed ().

is_enabled ()

This method is used to check if the web element is enabled or not. This method gives a Boolean value of either true or false depending on the condition of the element. If an element does not contain the enabled attribute, the is_enabled () method gives true value. Code Implementation with is_enabled ().

is_selected ()

This method is used to check if the web element is selected or not. This method gives a Boolean value of either true or false depending on the condition of the element. This method is used for radio buttons, checkboxes, and dropdowns, and so on. Code Implementation with is_selected ().

location

This method is used to get the web element location in terms of x and y coordinates. Code Implementation with location method.

In the next article, we will learn How To Handle Child Window, Frames, Alerts in Selenium Python

Related posts:

Sharing is caring.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Get our latest blog posts delivered to your inbox

Subscribe and get popular blog posts about software testing industry.

Rajkumar

Leave a Comment