diff --git a/examples/python/tests/elements/test_locators.py b/examples/python/tests/elements/test_locators.py index a8da9008909c..86f6c397f453 100644 --- a/examples/python/tests/elements/test_locators.py +++ b/examples/python/tests/elements/test_locators.py @@ -12,17 +12,17 @@ def test_find_by_classname(): def test_find_by_css_selector(): driver = webdriver.Chrome() - driver.get("https://www.selenium.dev/") + driver.get("https://www.selenium.dev/documentation/") - driver.find_element(By.CSS_SELECTOR, "#announcement-banner") + driver.find_element(By.CSS_SELECTOR, "#td-sidebar-menu") driver.quit() def test_find_by_id(): driver = webdriver.Chrome() - driver.get("https://www.selenium.dev/") + driver.get("https://www.selenium.dev/documentation/") - driver.find_element(By.ID, "announcement-banner") + driver.find_element(By.ID, "td-sidebar-menu") driver.quit() @@ -66,19 +66,57 @@ def test_find_by_xpath(): driver.quit() -def find_by_relative_locators(): +def test_relative_locators_above(): driver = webdriver.Chrome() - driver.get("https://www.selenium.dev/") + driver.get("https://www.selenium.dev/selenium/web/inputs.html") + + email_input = driver.find_element(locate_with(By.TAG_NAME, "input").above({ By.NAME: "password_input" })) + email_input.send_keys("test@test.com") + + driver.quit() + +def test_relative_locators_below(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/selenium/web/inputs.html") + + password_input = driver.find_element(locate_with(By.TAG_NAME, "input").below({ By.NAME: "email_input" })) + password_input.send_keys("randompassword") + + driver.quit() - email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"}) +def test_relative_locators_to_the_left_of(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/selenium/web/inputs.html") + + button = driver.find_element(locate_with(By.TAG_NAME, "input").to_left_of({ By.NAME: "submit_input" })) + button.click() - password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"}) + driver.quit() - cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"}) +def test_relative_locators_to_the_right_of(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/selenium/web/inputs.html") - submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"}) + button = driver.find_element(locate_with(By.TAG_NAME, "input").to_right_of({ By.NAME: "reset_input" })) + button.click() - email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"}) + driver.quit() + +def test_relative_locators_near(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/selenium/web/inputs.html") - submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"}) + button = driver.find_element(locate_with(By.TAG_NAME, "input").near({ By.NAME: "week_input" })) + button.send_keys('someweek') + + driver.quit() + +def test_relative_locators_below_and_right_of(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/selenium/web/inputs.html") + + button = driver.find_element(locate_with(By.TAG_NAME, "input").below({ By.NAME: "week_input" }).to_right_of({ By.NAME: "button_input" })) + button.click() + + driver.quit() diff --git a/website_and_docs/content/documentation/webdriver/elements/locators.en.md b/website_and_docs/content/documentation/webdriver/elements/locators.en.md index d09e718e754c..ce003899dc0e 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.en.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.en.md @@ -472,7 +472,7 @@ we can locate the text field element using the fact that it is an "input" elemen By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel")); diff --git a/website_and_docs/content/documentation/webdriver/elements/locators.ja.md b/website_and_docs/content/documentation/webdriver/elements/locators.ja.md index 6ea5c5dcd6fc..ad6d940f828e 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.ja.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.ja.md @@ -462,7 +462,7 @@ we can locate the text field element using the fact that it is an "input" elemen By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel")); diff --git a/website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md b/website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md index b167bf70ac5f..04e5e60fe909 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md @@ -465,7 +465,7 @@ we can locate the text field element using the fact that it is an "input" elemen By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel")); diff --git a/website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md b/website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md index c395dd916640..d5288f7dd86d 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md @@ -465,7 +465,7 @@ we can locate the text field element using the fact that it is an "input" elemen By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}} {{< /tab >}} {{< tab header="CSharp" >}} 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 By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel")); {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));