Element State Playwright Python

Element State with Playwright Python

Written by

There are different states for an element, the developer chooses a state according to the product specifications. For example, the Login button on a login page is disabled till the username and password are filled in.

In this article, we will learn about checking different states the element could be in. The below methods can return an accurate state only if the developers are using standard attributes to make them attain the state. If the developer uses custom attributes or CSS to attain the state then try to follow the custom method.


Returns true if the element is checked otherwise false.



Returns true if the element is hidden (not shown in the UI) otherwise false.



Returns true if the element is visible in the UI, visibility means the element should be more than 1 px in size.



The element accepts user actions, if it does not accept(most places grayed out), then the element is disabled. Returns true if the element is disabled



This is the opposite of is_disabled



If a user can edit a field (text bar, textarea), then the field is enabled, this function returns true if the element is enabled.


Custom Method:

If the developer used custom CSS then the standard methods provided by the playwright tool won’t work. In such cases, you need to use the get_attribute function to get the value and proceed.


Author :

Senior Software Engineer in Test, with more than a decade of experience in automation tools like Selenium, Playwright, Protractor, and Puppeteer with Python, Java, and JS respectively.