Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more input types to Webdriver clear() #780

Merged
merged 1 commit into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions splinter/driver/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,14 @@ def tag_name(self):

def clear(self):
if self._element.get_attribute("type") in [
"textarea",
"text",
"email",
"number",
"password",
"search",
"tel",
"text",
"textarea",
"url",
]:
self._element.clear()

Expand Down
24 changes: 24 additions & 0 deletions tests/form_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,27 @@ def test_can_clear_tel_field_content(self):
self.browser.find_by_name("telephone").clear()
value = self.browser.find_by_name("telephone").value
self.assertFalse(value)

def test_can_clear_textarea_content(self):
elem = self.browser.find_by_name("description")
elem.fill("A box of widgets")
assert "A box of widgets" == elem.value

elem.clear()
assert "" == elem.value

def test_can_clear_search_content(self):
elem = self.browser.find_by_name("search_keyword")
elem.fill("widgets")
assert "widgets" == elem.value

elem.clear()
assert "" == elem.value

def test_can_clear_url_content(self):
elem = self.browser.find_by_name("url_input")
elem.fill("http://widgets.com")
assert "http://widgets.com" == elem.value

elem.clear()
assert "" == elem.value
5 changes: 5 additions & 0 deletions tests/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ <h1 id="firstheader">Example Last Header</h1>
<input type="text" name="lastname">
</form>

<form id='urlInput'>
URL input:<br>
<input type="url" name="url_input">
<br>
</form>

<a href="http://example.com/">Link for Example.com</a>
<a href="http://example.com/last">Link for Example.com</a>
Expand Down
15 changes: 15 additions & 0 deletions tests/test_flaskclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ def test_can_clear_text_field_content(self):
with self.assertRaises(NotImplementedError):
self.browser.find_by_name("query").first.clear()

def test_can_clear_textarea_content(self):
"flask should not be able to clear"
with self.assertRaises(NotImplementedError):
self.browser.find_by_name("description").first.clear()

def test_can_clear_search_content(self):
"flask should not be able to clear"
with self.assertRaises(NotImplementedError):
self.browser.find_by_name("search_keyword").first.clear()

def test_can_clear_url_content(self):
"flask should not be able to clear"
with self.assertRaises(NotImplementedError):
self.browser.find_by_name("url_input").first.clear()

def test_cant_switch_to_frame(self):
"flask should not be able to switch to frames"
with self.assertRaises(NotImplementedError) as cm:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_zopetestbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ def test_can_clear_text_field_content(self):
with self.assertRaises(NotImplementedError):
self.browser.find_by_name("query").first.clear()

def test_can_clear_textarea_content(self):
"flask should not be able to clear"
with self.assertRaises(NotImplementedError):
self.browser.find_by_name("description").first.clear()

def test_can_clear_search_content(self):
"flask should not be able to clear"
with self.assertRaises(NotImplementedError):
self.browser.find_by_name("search_keyword").first.clear()

def test_can_clear_url_content(self):
"flask should not be able to clear"
with self.assertRaises(NotImplementedError):
self.browser.find_by_name("url_input").first.clear()

def test_slowly_typing(self):
"""
zope.testbrowser won't support type method
Expand Down