Skip to content

Commit

Permalink
Merge 2465768 into 7ab64b3
Browse files Browse the repository at this point in the history
  • Loading branch information
digitronik committed Jun 4, 2019
2 parents 7ab64b3 + 2465768 commit a45d27c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/widgetastic/widget/base.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions testing/html/testing_page.html
Expand Up @@ -31,7 +31,9 @@ <h2 style="display: none;" id="invisible">This is invisible</h2>
<form id="testform">
<h3>test test</h3>
<input name="input1" type="text" />
<input name="input1_disabled" type="text" disabled/>
<input id="input2" type="checkbox" />
<input id="input2_disabled" type="checkbox" disabled/>
</form>
<hr/>
<table id="with-thead">
Expand Down
7 changes: 7 additions & 0 deletions testing/test_basic_widgets.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a45d27c

Please sign in to comment.