Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/support/expected_conditions_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 TimeoutException
21
from selenium.webdriver.common.by import By
22
from selenium.webdriver.remote.webelement import WebElement
23
from selenium.webdriver.support import expected_conditions as EC
24
from selenium.webdriver.support.wait import WebDriverWait
25
26
27
def test_any_of_true(driver, pages):
28
pages.load("simpleTest.html")
29
WebDriverWait(driver, 0.1).until(EC.any_of(EC.title_is("Nope"), EC.title_is("Hello WebDriver")))
30
31
32
def test_any_of_false(driver, pages):
33
pages.load("simpleTest.html")
34
with pytest.raises(TimeoutException):
35
WebDriverWait(driver, 0.1).until(EC.any_of(EC.title_is("Nope"), EC.title_is("Still Nope")))
36
37
38
def test_all_of_true(driver, pages):
39
pages.load("simpleTest.html")
40
results = WebDriverWait(driver, 0.1).until(
41
EC.all_of(EC.title_is("Hello WebDriver"), EC.visibility_of_element_located((By.ID, "oneline")))
42
)
43
assert results[0] is True
44
assert isinstance(results[1], WebElement)
45
46
47
def test_all_of_false(driver, pages):
48
pages.load("simpleTest.html")
49
with pytest.raises(TimeoutException):
50
WebDriverWait(driver, 0.1).until(EC.all_of(EC.title_is("Nope"), EC.title_is("Still Nope")))
51
52
53
def test_none_of_true(driver, pages):
54
pages.load("simpleTest.html")
55
WebDriverWait(driver, 0.1).until(EC.none_of(EC.title_is("Nope"), EC.title_is("Still Nope")))
56
57
58
def test_none_of_false(driver, pages):
59
pages.load("simpleTest.html")
60
with pytest.raises(TimeoutException):
61
WebDriverWait(driver, 0.1).until(EC.none_of(EC.title_is("Nope"), EC.title_is("Hello WebDriver")))
62
63
64
def test_clickable_locator_true(driver, pages):
65
pages.load("simpleTest.html")
66
WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable((By.ID, "multilinelink")))
67
68
69
def test_clickable_locator_false(driver, pages):
70
pages.load("simpleTest.html")
71
with pytest.raises(TimeoutException):
72
# text element, should not be clickable
73
WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable((By.ID, "hiddenline")))
74
75
76
def test_clickable_element_true(driver, pages):
77
pages.load("simpleTest.html")
78
target = (By.ID, "multilinelink")
79
element = driver.find_element(*target) # grab element at locator
80
WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable(element))
81
82
83
def test_clickable_element_false(driver, pages):
84
pages.load("simpleTest.html")
85
with pytest.raises(TimeoutException):
86
target = (By.ID, "hiddenline") # text, should not be clickable
87
element = driver.find_element(*target) # grab element at locator
88
WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable(element))
89
90