Path: blob/trunk/py/test/selenium/webdriver/common/driver_element_finding_tests.py
4036 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import pytest1819from selenium.common.exceptions import InvalidSelectorException, NoSuchElementException20from selenium.webdriver.common.by import By2122# By.ID positive232425def test_should_be_able_to_find_asingle_element_by_id(driver, pages):26pages.load("xhtmlTest.html")27element = driver.find_element(By.ID, "linkId")28assert element.get_attribute("id") == "linkId"293031def test_should_be_able_to_find_asingle_element_by_numeric_id(driver, pages):32pages.load("nestedElements.html")33element = driver.find_element(By.ID, "2")34assert element.get_attribute("id") == "2"353637def test_should_be_able_to_find_an_element_with_css_escape(driver, pages):38pages.load("idElements.html")39element = driver.find_element(By.ID, "with.dots")40assert element.get_attribute("id") == "with.dots"414243def test_should_be_able_to_find_multiple_elements_by_id(driver, pages):44pages.load("nestedElements.html")45elements = driver.find_elements(By.ID, "test_id")46assert len(elements) == 2474849def test_should_be_able_to_find_multiple_elements_by_numeric_id(driver, pages):50pages.load("nestedElements.html")51elements = driver.find_elements(By.ID, "2")52assert len(elements) == 8535455# By.ID negative565758def test_should_not_be_able_to_locate_by_id_asingle_element_that_does_not_exist(driver, pages):59pages.load("formPage.html")60with pytest.raises(NoSuchElementException):61driver.find_element(By.ID, "non_Existent_Button")626364def test_should_not_be_able_to_locate_by_id_multiple_elements_that_do_not_exist(driver, pages):65pages.load("formPage.html")66elements = driver.find_elements(By.ID, "non_Existent_Button")67assert len(elements) == 0686970def test_finding_asingle_element_by_empty_id_should_throw(driver, pages):71pages.load("formPage.html")72with pytest.raises(NoSuchElementException):73driver.find_element(By.ID, "")747576def test_finding_multiple_elements_by_empty_id_should_return_empty_list(driver, pages):77pages.load("formPage.html")78elements = driver.find_elements(By.ID, "")79assert len(elements) == 0808182def test_finding_asingle_element_by_id_with_space_should_throw(driver, pages):83pages.load("formPage.html")84with pytest.raises(NoSuchElementException):85driver.find_element(By.ID, "nonexistent button")868788def test_finding_multiple_elements_by_id_with_space_should_return_empty_list(driver, pages):89pages.load("formPage.html")90elements = driver.find_elements(By.ID, "nonexistent button")91assert len(elements) == 0929394def test_no_such_element_error(driver, pages):95pages.load("formPage.html")96msg = r"\/errors#nosuchelementexception"97with pytest.raises(NoSuchElementException, match=msg):98driver.find_element(By.ID, "non_Existent_Button")99100101# By.NAME positive102103104def test_should_be_able_to_find_asingle_element_by_name(driver, pages):105pages.load("formPage.html")106element = driver.find_element(By.NAME, "checky")107assert element.get_attribute("value") == "furrfu"108109110def test_should_be_able_to_find_multiple_elements_by_name(driver, pages):111pages.load("nestedElements.html")112elements = driver.find_elements(By.NAME, "checky")113assert len(elements) > 1114115116def test_should_be_able_to_find_an_element_that_does_not_support_the_name_property(driver, pages):117pages.load("nestedElements.html")118element = driver.find_element(By.NAME, "div1")119assert element.get_attribute("name") == "div1"120121122# By.NAME negative123124125def test_should_not_be_able_to_locate_by_name_asingle_element_that_does_not_exist(driver, pages):126pages.load("formPage.html")127with pytest.raises(NoSuchElementException):128driver.find_element(By.NAME, "non_Existent_Button")129130131def test_should_not_be_able_to_locate_by_name_multiple_elements_that_do_not_exist(driver, pages):132pages.load("formPage.html")133elements = driver.find_elements(By.NAME, "non_Existent_Button")134assert len(elements) == 0135136137def test_finding_asingle_element_by_empty_name_should_throw(driver, pages):138pages.load("formPage.html")139with pytest.raises(NoSuchElementException):140driver.find_element(By.NAME, "")141142143def test_finding_multiple_elements_by_empty_name_should_return_empty_list(driver, pages):144pages.load("formPage.html")145elements = driver.find_elements(By.NAME, "")146assert len(elements) == 0147148149def test_finding_asingle_element_by_name_with_space_should_throw(driver, pages):150pages.load("formPage.html")151with pytest.raises(NoSuchElementException):152driver.find_element(By.NAME, "nonexistent button")153154155def test_finding_multiple_elements_by_name_with_space_should_return_empty_list(driver, pages):156pages.load("formPage.html")157elements = driver.find_elements(By.NAME, "nonexistent button")158assert len(elements) == 0159160161# By.TAG_NAME positive162163164def test_should_be_able_to_find_asingle_element_by_tag_name(driver, pages):165pages.load("formPage.html")166element = driver.find_element(By.TAG_NAME, "input")167assert element.tag_name.lower() == "input"168169170def test_should_be_able_to_find_multiple_elements_by_tag_name(driver, pages):171pages.load("formPage.html")172elements = driver.find_elements(By.TAG_NAME, "input")173assert len(elements) > 1174175176# By.TAG_NAME negative177178179def test_should_not_be_able_to_locate_by_tag_name_asingle_element_that_does_not_exist(driver, pages):180pages.load("formPage.html")181with pytest.raises(NoSuchElementException):182driver.find_element(By.TAG_NAME, "non_Existent_Button")183184185def test_should_not_be_able_to_locate_by_tag_name_multiple_elements_that_do_not_exist(driver, pages):186pages.load("formPage.html")187elements = driver.find_elements(By.TAG_NAME, "non_Existent_Button")188assert len(elements) == 0189190191@pytest.mark.xfail_firefox(reason="unlike chrome, firefox raises NoSuchElementException")192@pytest.mark.xfail_remote(reason="unlike chrome, firefox raises NoSuchElementException")193@pytest.mark.xfail_safari(reason="unlike chrome, safari raises NoSuchElementException")194def test_finding_asingle_element_by_empty_tag_name_should_throw(driver, pages):195pages.load("formPage.html")196with pytest.raises(InvalidSelectorException):197driver.find_element(By.TAG_NAME, "")198199200@pytest.mark.xfail_firefox(reason="unlike chrome, firefox returns an empty list")201@pytest.mark.xfail_remote(reason="unlike chrome, firefox returns an empty list")202@pytest.mark.xfail_safari(reason="unlike chrome, safari returns an empty list")203def test_finding_multiple_elements_by_empty_tag_name_should_throw(driver, pages):204pages.load("formPage.html")205with pytest.raises(InvalidSelectorException):206driver.find_elements(By.TAG_NAME, "")207208209def test_finding_asingle_element_by_tag_name_with_space_should_throw(driver, pages):210pages.load("formPage.html")211with pytest.raises(NoSuchElementException):212driver.find_element(By.TAG_NAME, "nonexistent button")213214215def test_finding_multiple_elements_by_tag_name_with_space_should_return_empty_list(driver, pages):216pages.load("formPage.html")217elements = driver.find_elements(By.TAG_NAME, "nonexistent button")218assert len(elements) == 0219220221# By.CLASS_NAME positive222223224def test_should_be_able_to_find_asingle_element_by_class(driver, pages):225pages.load("xhtmlTest.html")226element = driver.find_element(By.CLASS_NAME, "extraDiv")227assert "Another div starts here." in element.text228229230def test_should_be_able_to_find_multiple_elements_by_class_name(driver, pages):231pages.load("xhtmlTest.html")232elements = driver.find_elements(By.CLASS_NAME, "nameC")233assert len(elements) > 1234235236def test_should_find_element_by_class_when_it_is_the_first_name_among_many(driver, pages):237pages.load("xhtmlTest.html")238element = driver.find_element(By.CLASS_NAME, "nameA")239assert element.text == "An H2 title"240241242def test_should_find_element_by_class_when_it_is_the_last_name_among_many(driver, pages):243pages.load("xhtmlTest.html")244element = driver.find_element(By.CLASS_NAME, "nameC")245assert element.text == "An H2 title"246247248def test_should_find_element_by_class_when_it_is_in_the_middle_among_many(driver, pages):249pages.load("xhtmlTest.html")250element = driver.find_element(By.CLASS_NAME, "nameBnoise")251assert element.text == "An H2 title"252253254def test_should_find_element_by_class_when_its_name_is_surrounded_by_whitespace(driver, pages):255pages.load("xhtmlTest.html")256element = driver.find_element(By.CLASS_NAME, "spaceAround")257assert element.text == "Spaced out"258259260def test_should_find_elements_by_class_when_its_name_is_surrounded_by_whitespace(driver, pages):261pages.load("xhtmlTest.html")262elements = driver.find_elements(By.CLASS_NAME, "spaceAround")263assert len(elements) == 1264assert elements[0].text == "Spaced out"265266267# By.CLASS_NAME negative268269270def test_should_not_find_element_by_class_when_the_name_queried_is_shorter_than_candidate_name(driver, pages):271pages.load("xhtmlTest.html")272with pytest.raises(NoSuchElementException):273driver.find_element(By.CLASS_NAME, "name_B")274275276@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")277def test_finding_asingle_element_by_empty_class_name_should_throw(driver, pages):278pages.load("xhtmlTest.html")279msg = r"\/errors#invalidselectorexception"280with pytest.raises(InvalidSelectorException, match=msg):281driver.find_element(By.CLASS_NAME, "")282283284@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")285def test_finding_multiple_elements_by_empty_class_name_should_throw(driver, pages):286pages.load("xhtmlTest.html")287with pytest.raises(InvalidSelectorException):288driver.find_elements(By.CLASS_NAME, "")289290291def test_finding_asingle_element_by_compound_class_name_should_throw(driver, pages):292pages.load("xhtmlTest.html")293with pytest.raises(InvalidSelectorException):294driver.find_element(By.CLASS_NAME, "a b")295296297@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")298def test_finding_asingle_element_by_invalid_class_name_should_throw(driver, pages):299pages.load("xhtmlTest.html")300with pytest.raises(InvalidSelectorException):301driver.find_element(By.CLASS_NAME, "!@#$%^&*")302303304@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")305def test_finding_multiple_elements_by_invalid_class_name_should_throw(driver, pages):306pages.load("xhtmlTest.html")307with pytest.raises(InvalidSelectorException):308driver.find_elements(By.CLASS_NAME, "!@#$%^&*")309310311# By.XPATH positive312313314def test_should_be_able_to_find_asingle_element_by_xpath(driver, pages):315pages.load("xhtmlTest.html")316element = driver.find_element(By.XPATH, "//h1")317assert element.text == "XHTML Might Be The Future"318319320def test_should_be_able_to_find_multiple_elements_by_xpath(driver, pages):321pages.load("xhtmlTest.html")322elements = driver.find_elements(By.XPATH, "//div")323assert len(elements) == 13324325326def test_should_be_able_to_find_many_elements_repeatedly_by_xpath(driver, pages):327pages.load("xhtmlTest.html")328xpath = "//node()[contains(@id,'id')]"329assert len(driver.find_elements(By.XPATH, xpath)) == 3330331xpath = "//node()[contains(@id,'nope')]"332assert len(driver.find_elements(By.XPATH, xpath)) == 0333334335def test_should_be_able_to_identify_elements_by_class(driver, pages):336pages.load("xhtmlTest.html")337header = driver.find_element(By.XPATH, "//h1[@class='header']")338assert header.text == "XHTML Might Be The Future"339340341def test_should_be_able_to_find_an_element_by_xpath_with_multiple_attributes(driver, pages):342pages.load("formPage.html")343element = driver.find_element(By.XPATH, "//form[@name='optional']/input[@type='submit' and @value='Click!']")344assert element.tag_name.lower() == "input"345assert element.get_attribute("value") == "Click!"346347348def test_finding_alink_by_xpath_should_locate_an_element_with_the_given_text(driver, pages):349pages.load("xhtmlTest.html")350element = driver.find_element(By.XPATH, "//a[text()='click me']")351assert element.text == "click me"352353354def test_finding_alink_by_xpath_using_contains_keyword_should_work(driver, pages):355pages.load("nestedElements.html")356element = driver.find_element(By.XPATH, "//a[contains(.,'hello world')]")357assert "hello world" in element.text358359360# @pytest.mark.xfail_chrome(raises=InvalidSelectorException)361# @pytest.mark.xfail_edge(raises=InvalidSelectorException)362# @pytest.mark.xfail_firefox(raises=InvalidSelectorException)363# @pytest.mark.xfail_remote(raises=InvalidSelectorException)364# @pytest.mark.xfail_safari(raises=NoSuchElementException)365# @pytest.mark.xfail_webkitgtk(raises=InvalidSelectorException)366# def test_Should_Be_Able_To_Find_Element_By_XPath_With_Namespace(driver, pages):367# pages.load("svgPage.html")368# element = driver.find_element(By.XPATH, "//svg:svg//svg:text")369# assert element.text == "Test Chart"370371372def test_should_be_able_to_find_element_by_xpath_in_xml_document(driver, pages):373pages.load("simple.xml")374element = driver.find_element(By.XPATH, "//foo")375assert "baz" in element.text376377378# By.XPATH negative379380381def test_should_throw_an_exception_when_there_is_no_link_to_click(driver, pages):382pages.load("xhtmlTest.html")383with pytest.raises(NoSuchElementException):384driver.find_element(By.XPATH, "//a[@id='Not here']")385386387@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")388def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_driver_find_element(389driver, pages390):391pages.load("formPage.html")392with pytest.raises(InvalidSelectorException):393driver.find_element(By.XPATH, "this][isnot][valid")394395396@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")397def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_driver_find_elements(398driver, pages399):400pages.load("formPage.html")401with pytest.raises(InvalidSelectorException):402driver.find_elements(By.XPATH, "this][isnot][valid")403404405@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")406def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_element_find_element(407driver, pages408):409pages.load("formPage.html")410body = driver.find_element(By.TAG_NAME, "body")411with pytest.raises(InvalidSelectorException):412body.find_element(By.XPATH, "this][isnot][valid")413414415@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")416def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_element_find_elements(417driver, pages418):419pages.load("formPage.html")420body = driver.find_element(By.TAG_NAME, "body")421with pytest.raises(InvalidSelectorException):422body.find_elements(By.XPATH, "this][isnot][valid")423424425@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")426def test_should_throw_invalid_selector_exception_when_xpath_returns_wrong_type_in_driver_find_element(driver, pages):427pages.load("formPage.html")428with pytest.raises(InvalidSelectorException):429driver.find_element(By.XPATH, "count(//input)")430431432@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")433def test_should_throw_invalid_selector_exception_when_xpath_returns_wrong_type_in_driver_find_elements(driver, pages):434pages.load("formPage.html")435with pytest.raises(InvalidSelectorException):436driver.find_elements(By.XPATH, "count(//input)")437438439@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")440def test_should_throw_invalid_selector_exception_when_xpath_returns_wrong_type_in_element_find_element(driver, pages):441pages.load("formPage.html")442body = driver.find_element(By.TAG_NAME, "body")443with pytest.raises(InvalidSelectorException):444body.find_element(By.XPATH, "count(//input)")445446447@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")448def test_should_throw_invalid_selector_exception_when_xpath_returns_wrong_type_in_element_find_elements(driver, pages):449pages.load("formPage.html")450body = driver.find_element(By.TAG_NAME, "body")451with pytest.raises(InvalidSelectorException):452body.find_elements(By.XPATH, "count(//input)")453454455# By.CSS_SELECTOR positive456457458def test_should_be_able_to_find_asingle_element_by_css_selector(driver, pages):459pages.load("xhtmlTest.html")460element = driver.find_element(By.CSS_SELECTOR, "div.content")461assert element.tag_name.lower() == "div"462assert element.get_attribute("class") == "content"463464465def test_should_be_able_to_find_multiple_elements_by_css_selector(driver, pages):466pages.load("xhtmlTest.html")467elements = driver.find_elements(By.CSS_SELECTOR, "p")468assert len(elements) > 1469470471def test_should_be_able_to_find_asingle_element_by_compound_css_selector(driver, pages):472pages.load("xhtmlTest.html")473element = driver.find_element(By.CSS_SELECTOR, "div.extraDiv, div.content")474assert element.tag_name.lower() == "div"475assert element.get_attribute("class") == "content"476477478def test_should_be_able_to_find_multiple_elements_by_compound_css_selector(driver, pages):479pages.load("xhtmlTest.html")480elements = driver.find_elements(By.CSS_SELECTOR, "div.extraDiv, div.content")481assert len(elements) > 1482assert elements[0].get_attribute("class") == "content"483assert elements[1].get_attribute("class") == "extraDiv"484485486def test_should_be_able_to_find_an_element_by_boolean_attribute_using_css_selector(driver, pages):487pages.load("locators_tests/boolean_attribute_selected.html")488element = driver.find_element(By.CSS_SELECTOR, "option[selected='selected']")489assert element.get_attribute("value") == "two"490491492def test_should_be_able_to_find_an_element_by_boolean_attribute_using_short_css_selector(driver, pages):493pages.load("locators_tests/boolean_attribute_selected.html")494element = driver.find_element(By.CSS_SELECTOR, "option[selected]")495assert element.get_attribute("value") == "two"496497498def test_should_be_able_to_find_an_element_by_boolean_attribute_using_short_css_selector_on_html_4_page(driver, pages):499pages.load("locators_tests/boolean_attribute_selected_html4.html")500element = driver.find_element(By.CSS_SELECTOR, "option[selected]")501assert element.get_attribute("value") == "two"502503504# By.CSS_SELECTOR negative505506507def test_should_not_find_element_by_css_selector_when_there_is_no_such_element(driver, pages):508pages.load("xhtmlTest.html")509with pytest.raises(NoSuchElementException):510driver.find_element(By.CSS_SELECTOR, ".there-is-no-such-class")511512513def test_should_not_find_elements_by_css_selector_when_there_is_no_such_element(driver, pages):514pages.load("xhtmlTest.html")515elements = driver.find_elements(By.CSS_SELECTOR, ".there-is-no-such-class")516assert len(elements) == 0517518519@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")520def test_finding_asingle_element_by_empty_css_selector_should_throw(driver, pages):521pages.load("xhtmlTest.html")522with pytest.raises(InvalidSelectorException):523driver.find_element(By.CSS_SELECTOR, "")524525526@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")527def test_finding_multiple_elements_by_empty_css_selector_should_throw(driver, pages):528pages.load("xhtmlTest.html")529with pytest.raises(InvalidSelectorException):530driver.find_elements(By.CSS_SELECTOR, "")531532533@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")534def test_finding_asingle_element_by_invalid_css_selector_should_throw(driver, pages):535pages.load("xhtmlTest.html")536with pytest.raises(InvalidSelectorException):537driver.find_element(By.CSS_SELECTOR, "//a/b/c[@id='1']")538539540@pytest.mark.xfail_safari(reason="unlike chrome, safari raises TimeoutException")541def test_finding_multiple_elements_by_invalid_css_selector_should_throw(driver, pages):542pages.load("xhtmlTest.html")543with pytest.raises(InvalidSelectorException):544driver.find_elements(By.CSS_SELECTOR, "//a/b/c[@id='1']")545546547# By.LINK_TEXT positive548549550def test_should_be_able_to_find_alink_by_text(driver, pages):551pages.load("xhtmlTest.html")552link = driver.find_element(By.LINK_TEXT, "click me")553assert link.text == "click me"554555556def test_should_be_able_to_find_multiple_links_by_text(driver, pages):557pages.load("xhtmlTest.html")558elements = driver.find_elements(By.LINK_TEXT, "click me")559assert len(elements) == 2560561562def test_should_find_element_by_link_text_containing_equals_sign(driver, pages):563pages.load("xhtmlTest.html")564element = driver.find_element(By.LINK_TEXT, "Link=equalssign")565assert element.get_attribute("id") == "linkWithEqualsSign"566567568def test_should_find_multiple_elements_by_link_text_containing_equals_sign(driver, pages):569pages.load("xhtmlTest.html")570elements = driver.find_elements(By.LINK_TEXT, "Link=equalssign")571assert 1 == len(elements)572assert elements[0].get_attribute("id") == "linkWithEqualsSign"573574575def test_finds_by_link_text_on_xhtml_page(driver, pages):576pages.load("actualXhtmlPage.xhtml")577link_Text = "Foo"578element = driver.find_element(By.LINK_TEXT, link_Text)579assert element.text == link_Text580581582def test_link_with_formatting_tags(driver, pages):583pages.load("simpleTest.html")584elem = driver.find_element(By.ID, "links")585586res = elem.find_element(By.PARTIAL_LINK_TEXT, "link with formatting tags")587assert res.text == "link with formatting tags"588589590@pytest.mark.xfail_safari591def test_driver_can_get_link_by_link_test_ignoring_trailing_whitespace(driver, pages):592pages.load("simpleTest.html")593link = driver.find_element(By.LINK_TEXT, "link with trailing space")594assert link.get_attribute("id") == "linkWithTrailingSpace"595assert link.text == "link with trailing space"596597598# By.LINK_TEXT negative599600601def test_should_not_be_able_to_locate_by_link_text_asingle_element_that_does_not_exist(driver, pages):602pages.load("xhtmlTest.html")603with pytest.raises(NoSuchElementException):604driver.find_element(By.LINK_TEXT, "Not here either")605606607def test_should_not_be_able_to_locate_by_link_text_multiple_elements_that_do_not_exist(driver, pages):608pages.load("xhtmlTest.html")609elements = driver.find_elements(By.LINK_TEXT, "Not here either")610assert len(elements) == 0611612613# By.PARTIAL_LINK_TEXT positive614615616def test_should_be_able_to_find_multiple_elements_by_partial_link_text(driver, pages):617pages.load("xhtmlTest.html")618elements = driver.find_elements(By.PARTIAL_LINK_TEXT, "ick me")619assert len(elements) == 2620621622def test_should_be_able_to_find_asingle_element_by_partial_link_text(driver, pages):623pages.load("xhtmlTest.html")624element = driver.find_element(By.PARTIAL_LINK_TEXT, "anon")625assert "anon" in element.text626627628def test_should_find_element_by_partial_link_text_containing_equals_sign(driver, pages):629pages.load("xhtmlTest.html")630element = driver.find_element(By.PARTIAL_LINK_TEXT, "Link=")631assert element.get_attribute("id") == "linkWithEqualsSign"632633634def test_should_find_multiple_elements_by_partial_link_text_containing_equals_sign(driver, pages):635pages.load("xhtmlTest.html")636elements = driver.find_elements(By.PARTIAL_LINK_TEXT, "Link=")637assert len(elements) == 1638assert elements[0].get_attribute("id") == "linkWithEqualsSign"639640641# Misc tests642643644def test_driver_should_be_able_to_find_elements_after_loading_more_than_one_page_at_atime(driver, pages):645pages.load("formPage.html")646pages.load("xhtmlTest.html")647link = driver.find_element(By.LINK_TEXT, "click me")648assert link.text == "click me"649650651# You don't want to ask why this is here652653654def test_when_finding_by_name_should_not_return_by_id(driver, pages):655pages.load("formPage.html")656657element = driver.find_element(By.NAME, "id-name1")658assert element.get_attribute("value") == "name"659660element = driver.find_element(By.ID, "id-name1")661assert element.get_attribute("value") == "id"662663element = driver.find_element(By.NAME, "id-name2")664assert element.get_attribute("value") == "name"665666element = driver.find_element(By.ID, "id-name2")667assert element.get_attribute("value") == "id"668669670def test_should_be_able_to_find_ahidden_elements_by_name(driver, pages):671pages.load("formPage.html")672element = driver.find_element(By.NAME, "hidden")673assert element.get_attribute("name") == "hidden"674675676def test_should_not_be_able_to_find_an_element_on_a_blank_page(driver, pages):677driver.get("about:blank")678with pytest.raises(NoSuchElementException):679driver.find_element(By.TAG_NAME, "a")680681682# custom finders tests683684685def test_register_and_get_custom_finder():686By.register_custom_finder("custom", "custom strategy")687assert By.get_finder("custom") == "custom strategy"688689690def test_get_nonexistent_finder():691assert By.get_finder("nonexistent") is None692693694def test_clear_custom_finders():695By.register_custom_finder("custom", "custom strategy")696By.clear_custom_finders()697assert By.get_finder("custom") is None698699700