Метод элемента is_enabled () - Selenium Python

Опубликовано: 22 Марта, 2022

Модуль Python Selenium создан для автоматического тестирования с помощью Python. Привязки Selenium Python предоставляют простой API для написания функциональных / приемочных тестов с использованием Selenium WebDriver. Чтобы открыть веб-страницу с помощью Selenium Python, оформление заказа - Переход по ссылкам с использованием метода get - Selenium Python. Просто возможность пойти куда-нибудь не так уж и полезна. Что нам действительно нужно, так это взаимодействовать со страницами или, точнее, с элементами HTML внутри страницы. Существует несколько стратегий поиска элемента с помощью Selenium, checkout - Locating Strategies.

This article revolves around how to use is_enabled method in Selenium. is_enabled method is used to check if element is enabled or not. It returns a boolean value True or False.

Syntax –
element.is_enabled()

Example –

<a href="https://www.geeksforgeeks.org/" id="link" />Text Here</a>

To find an element one needs to use one of the locating strategies, For example,

element = driver.find_element_by_id("link")
element = driver.find_element_by_xpath("//a[@id="link"]")

Also, to find multiple elements, we can use –

elements = driver.find_elements_by_id("link")

Now one can check if this element is being displayed with

text_length = element.is_enabled()

How to use is_enabled element method in Selenium Python ?

Let’s use https://www.geeksforgeeks.org/ to illustrate this method in Selenium Python . Here we gcheck visibility of courses tab in navigation bar at geeksforgeeks.
Program –

# import webdriver
from selenium import webdriver
  
# create webdriver object
driver = webdriver.Firefox()
  
# get geeksforgeeks.org
  
# get element 
element = driver.find_element_by_link_text("Courses")
  
# print value
print(element.is_enabled())

Output-

Terminal Output –

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

Previous
is_selected() element method - Selenium Python
Next
is_displayed() element method - Selenium Python
Recommended Articles
Page :
Article Contributed By :
NaveenArora
@NaveenArora
Vote for difficulty
Article Tags :
  • Python-selenium
  • selenium
  • Python
Report Issue
Python

РЕКОМЕНДУЕМЫЕ СТАТЬИ