d1d8dd571dfce33cc964162f14715f9d68652776
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / retrieval / find_element_from_element.py
1 import pytest
2
3
4 from tests.support.asserts import assert_error, assert_success
5 from tests.support.inline import inline
6
7
8 def find_element(session, element, using, value):
9     return session.transport.send("POST",
10                                   "session/%s/element/%s/element" % (session.session_id, element),
11                                   {"using": using, "value": value})
12
13
14 @pytest.mark.parametrize("using", ["a", True, None, 1, [], {}])
15 def test_invalid_using_argument(session, using):
16     # Step 1 - 2
17     response = find_element(session, "notReal", using, "value")
18     assert_error(response, "invalid argument")
19
20
21 @pytest.mark.parametrize("value", [None, [], {}])
22 def test_invalid_selector_argument(session, value):
23     # Step 3 - 4
24     response = find_element(session, "notReal", "css selector", value)
25     assert_error(response, "invalid argument")
26
27
28 def test_closed_context(session, create_window):
29     # Step 5
30     new_window = create_window()
31     session.window_handle = new_window
32     session.close()
33
34     response = find_element(session, "notReal", "css selector", "foo")
35
36     assert_error(response, "no such window")
37
38
39 @pytest.mark.parametrize("using,value",
40                          [("css selector", "#linkText"),
41                           ("link text", "full link text"),
42                           ("partial link text", "link text"),
43                           ("tag name", "a"),
44                           ("xpath", "//a")])
45 def test_find_element(session, using, value):
46     # Step 8 - 9
47     session.url = inline("<div><a href=# id=linkText>full link text</a></div>")
48     element = session.find.css("div", all=False)
49     response = find_element(session, element.id, using, value)
50     assert_success(response)
51
52
53 @pytest.mark.parametrize("using,value",[("css selector", "#wontExist")])
54 def test_no_element(session, using, value):
55     # Step 8 - 9
56     session.url = inline("<div></div>")
57     element = session.find.css("div", all=False)
58     response = find_element(session, element.id, using, value)
59     assert_error(response, "no such element")