Skip to content

Commit 9ccc041

Browse files
committed
Update tests per PR suggestion
Split the tests for relative locators and used a live page for the tests.
1 parent 49f4e58 commit 9ccc041

File tree

5 files changed

+70
-32
lines changed

5 files changed

+70
-32
lines changed

Diff for: examples/python/tests/elements/test_locators.py

+50-12
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ def test_find_by_classname():
1212

1313
def test_find_by_css_selector():
1414
driver = webdriver.Chrome()
15-
driver.get("https://www.selenium.dev/")
15+
driver.get("https://www.selenium.dev/documentation/")
1616

17-
driver.find_element(By.CSS_SELECTOR, "#announcement-banner")
17+
driver.find_element(By.CSS_SELECTOR, "#td-sidebar-menu")
1818

1919
driver.quit()
2020

2121
def test_find_by_id():
2222
driver = webdriver.Chrome()
23-
driver.get("https://www.selenium.dev/")
23+
driver.get("https://www.selenium.dev/documentation/")
2424

25-
driver.find_element(By.ID, "announcement-banner")
25+
driver.find_element(By.ID, "td-sidebar-menu")
2626

2727
driver.quit()
2828

@@ -66,19 +66,57 @@ def test_find_by_xpath():
6666

6767
driver.quit()
6868

69-
def find_by_relative_locators():
69+
def test_relative_locators_above():
7070
driver = webdriver.Chrome()
71-
driver.get("https://www.selenium.dev/")
71+
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
72+
73+
email_input = driver.find_element(locate_with(By.TAG_NAME, "input").above({ By.NAME: "password_input" }))
74+
email_input.send_keys("[email protected]")
75+
76+
driver.quit()
77+
78+
def test_relative_locators_below():
79+
driver = webdriver.Chrome()
80+
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
81+
82+
password_input = driver.find_element(locate_with(By.TAG_NAME, "input").below({ By.NAME: "email_input" }))
83+
password_input.send_keys("randompassword")
84+
85+
driver.quit()
7286

73-
email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"})
87+
def test_relative_locators_to_the_left_of():
88+
driver = webdriver.Chrome()
89+
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
90+
91+
button = driver.find_element(locate_with(By.TAG_NAME, "input").to_left_of({ By.NAME: "submit_input" }))
92+
button.click()
7493

75-
password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"})
94+
driver.quit()
7695

77-
cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"})
96+
def test_relative_locators_to_the_right_of():
97+
driver = webdriver.Chrome()
98+
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
7899

79-
submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"})
100+
button = driver.find_element(locate_with(By.TAG_NAME, "input").to_right_of({ By.NAME: "reset_input" }))
101+
button.click()
80102

81-
email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"})
103+
driver.quit()
104+
105+
def test_relative_locators_near():
106+
driver = webdriver.Chrome()
107+
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
82108

83-
submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"})
109+
button = driver.find_element(locate_with(By.TAG_NAME, "input").near({ By.NAME: "week_input" }))
110+
button.send_keys('someweek')
111+
112+
driver.quit()
113+
114+
def test_relative_locators_below_and_right_of():
115+
driver = webdriver.Chrome()
116+
driver.get("https://www.selenium.dev/selenium/web/inputs.html")
117+
118+
button = driver.find_element(locate_with(By.TAG_NAME, "input").below({ By.NAME: "week_input" }).to_right_of({ By.NAME: "button_input" }))
119+
button.click()
120+
121+
driver.quit()
84122

Diff for: website_and_docs/content/documentation/webdriver/elements/locators.en.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ we can locate the text field element using the fact that it is an "input" elemen
472472
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email"));
473473
{{< /tab >}}
474474
{{< tab header="Python" text=true >}}
475-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}}
475+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}}
476476
{{< /tab >}}
477477
{{< tab header="CSharp" >}}
478478
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
@@ -499,7 +499,7 @@ we can locate the cancel button element using the fact that it is a "button" ele
499499
By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit"));
500500
{{< /tab >}}
501501
{{< tab header="Python" text=true >}}
502-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}}
502+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}}
503503
{{< /tab >}}
504504
{{< tab header="CSharp" >}}
505505
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
@@ -526,7 +526,7 @@ we can locate the submit button element using the fact that it is a "button" ele
526526
By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel"));
527527
{{< /tab >}}
528528
{{< tab header="Python" text=true >}}
529-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}}
529+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}}
530530
{{< /tab >}}
531531
{{< tab header="CSharp" >}}
532532
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
@@ -555,7 +555,7 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc
555555
By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email"));
556556
{{< /tab >}}
557557
{{< tab header="Python" text=true >}}
558-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}}
558+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}}
559559
{{< /tab >}}
560560
{{< tab header="CSharp" >}}
561561
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
@@ -581,7 +581,7 @@ You can also chain locators if needed. Sometimes the element is most easily iden
581581
By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel"));
582582
{{< /tab >}}
583583
{{< tab header="Python" text=true >}}
584-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}}
584+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}}
585585
{{< /tab >}}
586586
{{< tab header="CSharp" >}}
587587
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));

Diff for: website_and_docs/content/documentation/webdriver/elements/locators.ja.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ we can locate the text field element using the fact that it is an "input" elemen
462462
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email"));
463463
{{< /tab >}}
464464
{{< tab header="Python" text=true >}}
465-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}}
465+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}}
466466
{{< /tab >}}
467467
{{< tab header="CSharp" >}}
468468
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
@@ -488,7 +488,7 @@ we can locate the cancel button element using the fact that it is a "button" ele
488488
By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit"));
489489
{{< /tab >}}
490490
{{< tab header="Python" text=true >}}
491-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}}
491+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}}
492492
{{< /tab >}}
493493
{{< tab header="CSharp" >}}
494494
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
@@ -514,7 +514,7 @@ we can locate the submit button element using the fact that it is a "button" ele
514514
By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel"));
515515
{{< /tab >}}
516516
{{< tab header="Python" text=true >}}
517-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}}
517+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}}
518518
{{< /tab >}}
519519
{{< tab header="CSharp" >}}
520520
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
@@ -542,7 +542,7 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc
542542
By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email"));
543543
{{< /tab >}}
544544
{{< tab header="Python" text=true >}}
545-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}}
545+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}}
546546
{{< /tab >}}
547547
{{< tab header="CSharp" >}}
548548
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
@@ -567,7 +567,7 @@ You can also chain locators if needed. Sometimes the element is most easily iden
567567
By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel"));
568568
{{< /tab >}}
569569
{{< tab header="Python" text=true >}}
570-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}}
570+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}}
571571
{{< /tab >}}
572572
{{< tab header="CSharp" >}}
573573
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));

Diff for: website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ we can locate the text field element using the fact that it is an "input" elemen
465465
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email"));
466466
{{< /tab >}}
467467
{{< tab header="Python" text=true >}}
468-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}}
468+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}}
469469
{{< /tab >}}
470470
{{< tab header="CSharp" >}}
471471
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
@@ -491,7 +491,7 @@ we can locate the cancel button element using the fact that it is a "button" ele
491491
By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit"));
492492
{{< /tab >}}
493493
{{< tab header="Python" text=true >}}
494-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}}
494+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}}
495495
{{< /tab >}}
496496
{{< tab header="CSharp" >}}
497497
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
@@ -517,7 +517,7 @@ we can locate the submit button element using the fact that it is a "button" ele
517517
By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel"));
518518
{{< /tab >}}
519519
{{< tab header="Python" text=true >}}
520-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}}
520+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}}
521521
{{< /tab >}}
522522
{{< tab header="CSharp" >}}
523523
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
@@ -545,7 +545,7 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc
545545
By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email"));
546546
{{< /tab >}}
547547
{{< tab header="Python" text=true >}}
548-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}}
548+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}}
549549
{{< /tab >}}
550550
{{< tab header="CSharp" >}}
551551
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
@@ -570,7 +570,7 @@ You can also chain locators if needed. Sometimes the element is most easily iden
570570
By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel"));
571571
{{< /tab >}}
572572
{{< tab header="Python" text=true >}}
573-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}}
573+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}}
574574
{{< /tab >}}
575575
{{< tab header="CSharp" >}}
576576
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));

Diff for: website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ we can locate the text field element using the fact that it is an "input" elemen
465465
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email"));
466466
{{< /tab >}}
467467
{{< tab header="Python" text=true >}}
468-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}}
468+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}}
469469
{{< /tab >}}
470470
{{< tab header="CSharp" >}}
471471
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
@@ -491,7 +491,7 @@ we can locate the cancel button element using the fact that it is a "button" ele
491491
By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit"));
492492
{{< /tab >}}
493493
{{< tab header="Python" text=true >}}
494-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}}
494+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}}
495495
{{< /tab >}}
496496
{{< tab header="CSharp" >}}
497497
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
@@ -517,7 +517,7 @@ we can locate the submit button element using the fact that it is a "button" ele
517517
By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel"));
518518
{{< /tab >}}
519519
{{< tab header="Python" text=true >}}
520-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}}
520+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}}
521521
{{< /tab >}}
522522
{{< tab header="CSharp" >}}
523523
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
@@ -545,7 +545,7 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc
545545
By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email"));
546546
{{< /tab >}}
547547
{{< tab header="Python" text=true >}}
548-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}}
548+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}}
549549
{{< /tab >}}
550550
{{< tab header="CSharp" >}}
551551
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
@@ -570,7 +570,7 @@ You can also chain locators if needed. Sometimes the element is most easily iden
570570
By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel"));
571571
{{< /tab >}}
572572
{{< tab header="Python" text=true >}}
573-
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}}
573+
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}}
574574
{{< /tab >}}
575575
{{< tab header="CSharp" >}}
576576
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));

0 commit comments

Comments
 (0)