Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/common/clear_tests.py
1865 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
import pytest
19
20
from selenium.common.exceptions import InvalidElementStateException
21
from selenium.webdriver.common.by import By
22
23
24
def test_writable_text_input_should_clear(driver, pages):
25
pages.load("readOnlyPage.html")
26
element = driver.find_element(By.ID, "writableTextInput")
27
element.clear()
28
assert "" == element.get_attribute("value")
29
30
31
@pytest.mark.xfail_chrome(reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743")
32
@pytest.mark.xfail_edge(reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743")
33
def test_text_input_should_not_clear_when_disabled(driver, pages):
34
pages.load("readOnlyPage.html")
35
element = driver.find_element(By.ID, "textInputNotEnabled")
36
assert not element.is_enabled()
37
with pytest.raises(InvalidElementStateException):
38
element.clear()
39
40
41
def test_text_input_should_not_clear_when_read_only(driver, pages):
42
pages.load("readOnlyPage.html")
43
element = driver.find_element(By.ID, "readOnlyTextInput")
44
with pytest.raises(InvalidElementStateException):
45
element.clear()
46
47
48
def test_writable_text_area_should_clear(driver, pages):
49
pages.load("readOnlyPage.html")
50
element = driver.find_element(By.ID, "writableTextArea")
51
element.clear()
52
assert "" == element.get_attribute("value")
53
54
55
@pytest.mark.xfail_chrome(reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743")
56
@pytest.mark.xfail_edge(reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743")
57
def test_text_area_should_not_clear_when_disabled(driver, pages):
58
pages.load("readOnlyPage.html")
59
element = driver.find_element(By.ID, "textAreaNotEnabled")
60
with pytest.raises(InvalidElementStateException):
61
element.clear()
62
63
64
def test_text_area_should_not_clear_when_read_only(driver, pages):
65
pages.load("readOnlyPage.html")
66
element = driver.find_element(By.ID, "textAreaReadOnly")
67
with pytest.raises(InvalidElementStateException):
68
element.clear()
69
70
71
def test_content_editable_area_should_clear(driver, pages):
72
pages.load("readOnlyPage.html")
73
element = driver.find_element(By.ID, "content-editable")
74
element.clear()
75
assert "" == element.text
76
77