diff --git a/src/widgetastic/widget/base.py b/src/widgetastic/widget/base.py index 4ad2f414..9cd3c7a5 100644 --- a/src/widgetastic/widget/base.py +++ b/src/widgetastic/widget/base.py @@ -323,7 +323,7 @@ def __element__(self): It uses :py:meth:`__locator__` to retrieve the locator and then it looks up the WebElement on the parent's browser. - If hte ``__locator__`` isbadly implemented and returns a ``WebElement`` instance, it returns + If the ``__locator__`` isbadly implemented and returns a ``WebElement`` instance, it returns it directly. You usually want this method to be intact. @@ -483,6 +483,18 @@ def is_displayed(self): """ return self.browser.is_displayed(self) + @property + def is_enabled(self): + """Check widget is enabled or not. + + The logic behind `is_enabled` is WebElement property. If `__locator__` not pointing to the + expected `WebElement`, you can always override this. + + Returns: + :py:class:`bool` + """ + return self.browser.element(self).is_enabled() + @logged() def wait_displayed(self, timeout='10s', delay=0.2): """Wait for the element to be displayed. Uses the :py:meth:`is_displayed` diff --git a/testing/html/testing_page.html b/testing/html/testing_page.html index 0c466e86..01ded906 100644 --- a/testing/html/testing_page.html +++ b/testing/html/testing_page.html @@ -31,7 +31,9 @@

test test

+ +

diff --git a/testing/test_basic_widgets.py b/testing/test_basic_widgets.py index bed731c3..41c145c4 100644 --- a/testing/test_basic_widgets.py +++ b/testing/test_basic_widgets.py @@ -16,6 +16,8 @@ class TestForm(View): input1 = TextInput(name='input1') input2 = Checkbox(id='input2') input3 = ColourInput(id='colourinput') + input4 = Checkbox(name='input1_disabled') + input5 = Checkbox(id='input2_disabled') fileinput = FileInput(id='fileinput') class AFillable(Fillable): @@ -60,6 +62,11 @@ def as_fill_value(self): with pytest.raises(DoNotReadThisWidget): form.fileinput.read() + assert form.input1.is_enabled + assert not form.input4.is_enabled + assert form.input2.is_enabled + assert not form.input5.is_enabled + def test_nested_views_read_fill(browser): class TestForm(View):