Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/common/element_equality_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
from selenium.webdriver.common.by import By
19
20
21
def test_same_element_looked_up_different_ways_should_be_equal(driver, pages):
22
pages.load("simpleTest.html")
23
body = driver.find_element(By.TAG_NAME, "body")
24
xbody = driver.find_elements(By.XPATH, "//body")[0]
25
26
assert body == xbody
27
28
29
def test_different_elements_are_not_equal(driver, pages):
30
pages.load("simpleTest.html")
31
body = driver.find_element(By.TAG_NAME, "body")
32
div = driver.find_element(By.TAG_NAME, "div")
33
34
assert body != div
35
36
37
def test_same_elements_found_different_ways_should_not_be_duplicated_in_aset(driver, pages):
38
pages.load("simpleTest.html")
39
body = driver.find_element(By.TAG_NAME, "body")
40
xbody = driver.find_elements(By.XPATH, "//body")
41
s = set(xbody)
42
s.add(body)
43
assert 1 == len(s)
44
45