From 0a30c87e2ca2332c5aebdb6f368a31d2c43179d9 Mon Sep 17 00:00:00 2001 From: Pablo Martinez Date: Tue, 27 Aug 2024 10:34:09 -0700 Subject: [PATCH 1/5] Update test_locators.py file to include examples Add examples to the python docs for locators --- .../python/tests/elements/test_locators.py | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/examples/python/tests/elements/test_locators.py b/examples/python/tests/elements/test_locators.py index 53b695b6fc83..de57c8b45772 100644 --- a/examples/python/tests/elements/test_locators.py +++ b/examples/python/tests/elements/test_locators.py @@ -1,2 +1,105 @@ +import pytest from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.relative_locator import locate_with + +def test_find_by_classname(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/") + + driver.find_element(By.CLASS_NAME, "td-home") + + driver.quit() + +def test_find_by_css_selector(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/") + + driver.find_element(By.CSS_SELECTOR, "#announcement-banner") + + driver.quit() + +def test_find_by_id(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/") + + driver.find_element(By.ID, "announcement-banner") + + driver.quit() + +def test_find_by_name(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/selenium/web/formPage.html") + + driver.find_element(By.NAME, "image") + + driver.quit() + +def test_find_by_link_text(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/") + + driver.find_element(By.LINK_TEXT, "Documentation") + + driver.quit() + +def test_find_by_partial_link_text(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/documentation/") + + driver.find_element(By.PARTIAL_LINK_TEXT, "Selenium script") + + driver.quit() + +def test_find_by_tag_name(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/") + + driver.find_element(By.TAG_NAME, "nav") + + driver.quit() + +def test_find_by_xpath(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/") + + driver.find_element(By.XPATH, "//a[@class=\"navbar-brand\"]") + + driver.quit() + +pytest.mark.skip(reason='the examples are tied to an image with an example, on the site') +def find_by_relative_locators(): + driver = webdriver.Chrome() + driver.get("https://www.selenium.dev/") + + email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"}) + + password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"}) + + cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"}) + + submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"}) + + email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"}) + + submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"}) + + +# def test_find_by_relative_locators(): +# driver = webdriver.Chrome() +# driver.get("https://www.selenium.dev/selenium/web/formPage.html") + +# locate_with(By.TAG_NAME, "input").above({ By.ID: "checkedchecky" }) + +# locate_with(By.TAG_NAME, "input").below({ By.ID: "checkedchecky" }) + +# locate_with(By.TAG_NAME, "select").to_left_of({ By.ID: "multi" }) + +# locate_with(By.TAG_NAME, "select").to_right_of({ By.NAME: "no-select" }) + +# locate_with(By.TAG_NAME, "p").near({By.ID: "lone_disabled_selected_radio"}) + +# locate_with(By.TAG_NAME, "select").to_right_of({ By.NAME: "no-select" }).below({ By.TAG_NAME: "form" }) + +# driver.quit() From 297b5ccb596add14a5b66e210501f5a86a1652cb Mon Sep 17 00:00:00 2001 From: Pablo Martinez Date: Tue, 27 Aug 2024 10:34:53 -0700 Subject: [PATCH 2/5] Remove and add examples --- .../python/tests/elements/test_locators.py | 19 ----- .../webdriver/elements/locators.en.md | 70 ++++++++----------- 2 files changed, 30 insertions(+), 59 deletions(-) diff --git a/examples/python/tests/elements/test_locators.py b/examples/python/tests/elements/test_locators.py index de57c8b45772..3e16d4820fdc 100644 --- a/examples/python/tests/elements/test_locators.py +++ b/examples/python/tests/elements/test_locators.py @@ -84,22 +84,3 @@ def find_by_relative_locators(): submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"}) - -# def test_find_by_relative_locators(): -# driver = webdriver.Chrome() -# driver.get("https://www.selenium.dev/selenium/web/formPage.html") - -# locate_with(By.TAG_NAME, "input").above({ By.ID: "checkedchecky" }) - -# locate_with(By.TAG_NAME, "input").below({ By.ID: "checkedchecky" }) - -# locate_with(By.TAG_NAME, "select").to_left_of({ By.ID: "multi" }) - -# locate_with(By.TAG_NAME, "select").to_right_of({ By.NAME: "no-select" }) - -# locate_with(By.TAG_NAME, "p").near({By.ID: "lone_disabled_selected_radio"}) - -# locate_with(By.TAG_NAME, "select").to_right_of({ By.NAME: "no-select" }).below({ By.TAG_NAME: "form" }) - -# 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 d08963fd063d..2a7afc154f73 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.en.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.en.md @@ -80,9 +80,8 @@ available in Selenium. WebDriver driver = new ChromeDriver(); driver.findElement(By.className("information")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.CLASS_NAME, "information") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -114,9 +113,8 @@ textbox, using css. WebDriver driver = new ChromeDriver(); driver.findElement(By.cssSelector("#fname")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.CSS_SELECTOR, "#fname") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L18" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -146,9 +144,8 @@ We will identify the Last Name field using it. WebDriver driver = new ChromeDriver(); driver.findElement(By.id("lname")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.ID, "lname") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L26" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -179,9 +176,8 @@ We will identify the Newsletter checkbox using it. WebDriver driver = new ChromeDriver(); driver.findElement(By.name("newsletter")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.NAME, "newsletter") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L34" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -210,9 +206,8 @@ In the HTML snippet shared, we have a link available, let's see how will we loca WebDriver driver = new ChromeDriver(); driver.findElement(By.linkText("Selenium Official Page")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.LINK_TEXT, "Selenium Official Page") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L42" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -242,9 +237,8 @@ In the HTML snippet shared, we have a link available, lets see how will we locat WebDriver driver = new ChromeDriver(); driver.findElement(By.partialLinkText("Official Page")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L50" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -272,9 +266,8 @@ From the above HTML snippet shared, lets identify the link, using its html tag " WebDriver driver = new ChromeDriver(); driver.findElement(By.tagName("a")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.TAG_NAME, "a") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L58" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -308,9 +301,8 @@ first name text box. Let us create locator for female radio button using xpath. WebDriver driver = new ChromeDriver(); driver.findElement(By.xpath("//input[@value='f']")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.XPATH, "//input[@value='f']") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L66" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -345,10 +337,8 @@ others it's as simple as setting a parameter in the FindElement function WebDriver driver = new ChromeDriver(); driver.findElement(By.className("information")); {{< /tab >}} - {{< tab header="Python" >}} - from selenium.webdriver.common.by import By - driver = webdriver.Chrome() - driver.find_element(By.CLASS_NAME, "information") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -454,8 +444,8 @@ we can locate the text field element using the fact that it is an "input" elemen {{< tab header="Java" >}} By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password")); {{< /tab >}} -{{< tab header="Python" >}} -email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); @@ -481,8 +471,8 @@ we can locate the text field element using the fact that it is an "input" elemen {{< tab header="Java" >}} By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email")); {{< /tab >}} -{{< tab header="Python" >}} -password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} {{< /tab >}} {{< tab header="CSharp" >}} var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email")); @@ -508,8 +498,8 @@ we can locate the cancel button element using the fact that it is a "button" ele {{< tab header="Java" >}} By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit")); {{< /tab >}} -{{< tab header="Python" >}} -cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} {{< /tab >}} {{< tab header="CSharp" >}} var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit")); @@ -535,8 +525,8 @@ we can locate the submit button element using the fact that it is a "button" ele {{< tab header="Java" >}} By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel")); {{< /tab >}} -{{< tab header="Python" >}} -submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel")); @@ -564,8 +554,8 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc {{< tab header="Java" >}} By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email")); {{< /tab >}} -{{< tab header="Python" >}} -email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email")); @@ -590,8 +580,8 @@ You can also chain locators if needed. Sometimes the element is most easily iden {{< tab header="Java" >}} By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel")); {{< /tab >}} -{{< tab header="Python" >}} -submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L85" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel")); From 32215dc7b445983392e689c5b90f0ce458ec29a1 Mon Sep 17 00:00:00 2001 From: Pablo Martinez Date: Tue, 27 Aug 2024 11:23:13 -0700 Subject: [PATCH 3/5] Update the other languages for locators python docs --- .../webdriver/elements/locators.ja.md | 70 ++++++++----------- .../webdriver/elements/locators.pt-br.md | 70 ++++++++----------- .../webdriver/elements/locators.zh-cn.md | 70 ++++++++----------- 3 files changed, 90 insertions(+), 120 deletions(-) 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 28b11bcd66cc..e0c4567ddc8a 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.ja.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.ja.md @@ -78,9 +78,8 @@ available in Selenium. WebDriver driver = new ChromeDriver(); driver.findElement(By.className("information")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.CLASS_NAME, "information") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -111,9 +110,8 @@ textbox, using css. WebDriver driver = new ChromeDriver(); driver.findElement(By.cssSelector("#fname")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.CSS_SELECTOR, "#fname") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L18" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -142,9 +140,8 @@ We will identify the Last Name field using it. WebDriver driver = new ChromeDriver(); driver.findElement(By.id("lname")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.ID, "lname") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L26" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -174,9 +171,8 @@ We will identify the Newsletter checkbox using it. WebDriver driver = new ChromeDriver(); driver.findElement(By.name("newsletter")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.NAME, "newsletter") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L34" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -204,9 +200,8 @@ In the HTML snippet shared, we have a link available, lets see how will we locat WebDriver driver = new ChromeDriver(); driver.findElement(By.linkText("Selenium Official Page")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.LINK_TEXT, "Selenium Official Page") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L42" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -235,9 +230,8 @@ In the HTML snippet shared, we have a link available, lets see how will we locat WebDriver driver = new ChromeDriver(); driver.findElement(By.partialLinkText("Official Page")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L50" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -264,9 +258,8 @@ From the above HTML snippet shared, lets identify the link, using its html tag " WebDriver driver = new ChromeDriver(); driver.findElement(By.tagName("a")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.TAG_NAME, "a") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L58" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -299,9 +292,8 @@ first name text box. Let us create locator for female radio button using xpath. WebDriver driver = new ChromeDriver(); driver.findElement(By.xpath("//input[@value='f']")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.XPATH, "//input[@value='f']") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L66" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -335,10 +327,8 @@ others it's as simple as setting a parameter in the FindElement function WebDriver driver = new ChromeDriver(); driver.findElement(By.className("information")); {{< /tab >}} - {{< tab header="Python" >}} - from selenium.webdriver.common.by import By - driver = webdriver.Chrome() - driver.find_element(By.CLASS_NAME, "information") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -445,8 +435,8 @@ we can locate the text field element using the fact that it is an "input" elemen {{< tab header="Java" >}} By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password")); {{< /tab >}} -{{< tab header="Python" >}} -email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); @@ -471,8 +461,8 @@ we can locate the text field element using the fact that it is an "input" elemen {{< tab header="Java" >}} By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email")); {{< /tab >}} -{{< tab header="Python" >}} -password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} {{< /tab >}} {{< tab header="CSharp" >}} var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email")); @@ -497,8 +487,8 @@ we can locate the cancel button element using the fact that it is a "button" ele {{< tab header="Java" >}} By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit")); {{< /tab >}} -{{< tab header="Python" >}} -cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} {{< /tab >}} {{< tab header="CSharp" >}} var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit")); @@ -523,8 +513,8 @@ we can locate the submit button element using the fact that it is a "button" ele {{< tab header="Java" >}} By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel")); {{< /tab >}} -{{< tab header="Python" >}} -submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel")); @@ -551,8 +541,8 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc {{< tab header="Java" >}} By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email")); {{< /tab >}} -{{< tab header="Python" >}} -email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email")); @@ -576,8 +566,8 @@ You can also chain locators if needed. Sometimes the element is most easily iden {{< tab header="Java" >}} By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel")); {{< /tab >}} -{{< tab header="Python" >}} -submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L85" >}} {{< /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 de57a4812d37..c70bb9e9a2d7 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 @@ -81,9 +81,8 @@ available in Selenium. WebDriver driver = new ChromeDriver(); driver.findElement(By.className("information")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.CLASS_NAME, "information") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -114,9 +113,8 @@ textbox, using css. WebDriver driver = new ChromeDriver(); driver.findElement(By.cssSelector("#fname")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.CSS_SELECTOR, "#fname") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L18" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -145,9 +143,8 @@ We will identify the Last Name field using it. WebDriver driver = new ChromeDriver(); driver.findElement(By.id("lname")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.ID, "lname") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L26" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -177,9 +174,8 @@ We will identify the Newsletter checkbox using it. WebDriver driver = new ChromeDriver(); driver.findElement(By.name("newsletter")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.NAME, "newsletter") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L34" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -207,9 +203,8 @@ In the HTML snippet shared, we have a link available, lets see how will we locat WebDriver driver = new ChromeDriver(); driver.findElement(By.linkText("Selenium Official Page")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.LINK_TEXT, "Selenium Official Page") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L42" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -238,9 +233,8 @@ In the HTML snippet shared, we have a link available, lets see how will we locat WebDriver driver = new ChromeDriver(); driver.findElement(By.partialLinkText("Official Page")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L50" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -267,9 +261,8 @@ From the above HTML snippet shared, lets identify the link, using its html tag " WebDriver driver = new ChromeDriver(); driver.findElement(By.tagName("a")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.TAG_NAME, "a") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L58" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -302,9 +295,8 @@ first name text box. Let us create locator for female radio button using xpath. WebDriver driver = new ChromeDriver(); driver.findElement(By.xpath("//input[@value='f']")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.XPATH, "//input[@value='f']") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L66" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -338,10 +330,8 @@ others it's as simple as setting a parameter in the FindElement function WebDriver driver = new ChromeDriver(); driver.findElement(By.className("information")); {{< /tab >}} - {{< tab header="Python" >}} - from selenium.webdriver.common.by import By - driver = webdriver.Chrome() - driver.find_element(By.CLASS_NAME, "information") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -448,8 +438,8 @@ we can locate the text field element using the fact that it is an "input" elemen {{< tab header="Java" >}} By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password")); {{< /tab >}} -{{< tab header="Python" >}} -email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); @@ -474,8 +464,8 @@ we can locate the text field element using the fact that it is an "input" elemen {{< tab header="Java" >}} By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email")); {{< /tab >}} -{{< tab header="Python" >}} -password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} {{< /tab >}} {{< tab header="CSharp" >}} var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email")); @@ -500,8 +490,8 @@ we can locate the cancel button element using the fact that it is a "button" ele {{< tab header="Java" >}} By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit")); {{< /tab >}} -{{< tab header="Python" >}} -cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} {{< /tab >}} {{< tab header="CSharp" >}} var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit")); @@ -526,8 +516,8 @@ we can locate the submit button element using the fact that it is a "button" ele {{< tab header="Java" >}} By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel")); {{< /tab >}} -{{< tab header="Python" >}} -submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel")); @@ -554,8 +544,8 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc {{< tab header="Java" >}} By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email")); {{< /tab >}} -{{< tab header="Python" >}} -email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email")); @@ -579,8 +569,8 @@ You can also chain locators if needed. Sometimes the element is most easily iden {{< tab header="Java" >}} By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel")); {{< /tab >}} -{{< tab header="Python" >}} -submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L85" >}} {{< /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 b8e38f81faff..e4a92f1b881a 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 @@ -81,9 +81,8 @@ available in Selenium. WebDriver driver = new ChromeDriver(); driver.findElement(By.className("information")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.CLASS_NAME, "information") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -114,9 +113,8 @@ textbox, using css. WebDriver driver = new ChromeDriver(); driver.findElement(By.cssSelector("#fname")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.CSS_SELECTOR, "#fname") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L18" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -145,9 +143,8 @@ We will identify the Last Name field using it. WebDriver driver = new ChromeDriver(); driver.findElement(By.id("lname")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.ID, "lname") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L26" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -177,9 +174,8 @@ We will identify the Newsletter checkbox using it. WebDriver driver = new ChromeDriver(); driver.findElement(By.name("newsletter")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.NAME, "newsletter") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L34" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -207,9 +203,8 @@ In the HTML snippet shared, we have a link available, lets see how will we locat WebDriver driver = new ChromeDriver(); driver.findElement(By.linkText("Selenium Official Page")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.LINK_TEXT, "Selenium Official Page") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L42" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -238,9 +233,8 @@ In the HTML snippet shared, we have a link available, lets see how will we locat WebDriver driver = new ChromeDriver(); driver.findElement(By.partialLinkText("Official Page")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L50" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -267,9 +261,8 @@ From the above HTML snippet shared, lets identify the link, using its html tag " WebDriver driver = new ChromeDriver(); driver.findElement(By.tagName("a")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.TAG_NAME, "a") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L58" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -302,9 +295,8 @@ first name text box. Let us create locator for female radio button using xpath. WebDriver driver = new ChromeDriver(); driver.findElement(By.xpath("//input[@value='f']")); {{< /tab >}} - {{< tab header="Python" >}} - driver = webdriver.Chrome() - driver.find_element(By.XPATH, "//input[@value='f']") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L66" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -338,10 +330,8 @@ others it's as simple as setting a parameter in the FindElement function WebDriver driver = new ChromeDriver(); driver.findElement(By.className("information")); {{< /tab >}} - {{< tab header="Python" >}} - from selenium.webdriver.common.by import By - driver = webdriver.Chrome() - driver.find_element(By.CLASS_NAME, "information") + {{< tab header="Python" text=true >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -448,8 +438,8 @@ we can locate the text field element using the fact that it is an "input" elemen {{< tab header="Java" >}} By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password")); {{< /tab >}} -{{< tab header="Python" >}} -email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); @@ -474,8 +464,8 @@ we can locate the text field element using the fact that it is an "input" elemen {{< tab header="Java" >}} By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email")); {{< /tab >}} -{{< tab header="Python" >}} -password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} {{< /tab >}} {{< tab header="CSharp" >}} var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email")); @@ -500,8 +490,8 @@ we can locate the cancel button element using the fact that it is a "button" ele {{< tab header="Java" >}} By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit")); {{< /tab >}} -{{< tab header="Python" >}} -cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} {{< /tab >}} {{< tab header="CSharp" >}} var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit")); @@ -526,8 +516,8 @@ we can locate the submit button element using the fact that it is a "button" ele {{< tab header="Java" >}} By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel")); {{< /tab >}} -{{< tab header="Python" >}} -submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel")); @@ -554,8 +544,8 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc {{< tab header="Java" >}} By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email")); {{< /tab >}} -{{< tab header="Python" >}} -email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email")); @@ -579,8 +569,8 @@ You can also chain locators if needed. Sometimes the element is most easily iden {{< tab header="Java" >}} By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel")); {{< /tab >}} -{{< tab header="Python" >}} -submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"}) +{{< tab header="Python" text=true >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L85" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel")); From 49f4e587c4ec424c627d8dde2dc0e3d4d03d0b23 Mon Sep 17 00:00:00 2001 From: Pablo Martinez Date: Fri, 20 Sep 2024 17:49:10 -0700 Subject: [PATCH 4/5] Removed pytest --- .../python/tests/elements/test_locators.py | 2 -- .../webdriver/elements/locators.en.md | 30 +++++++++---------- .../webdriver/elements/locators.ja.md | 30 +++++++++---------- .../webdriver/elements/locators.pt-br.md | 30 +++++++++---------- .../webdriver/elements/locators.zh-cn.md | 30 +++++++++---------- 5 files changed, 60 insertions(+), 62 deletions(-) diff --git a/examples/python/tests/elements/test_locators.py b/examples/python/tests/elements/test_locators.py index 3e16d4820fdc..a8da9008909c 100644 --- a/examples/python/tests/elements/test_locators.py +++ b/examples/python/tests/elements/test_locators.py @@ -1,4 +1,3 @@ -import pytest from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.relative_locator import locate_with @@ -67,7 +66,6 @@ def test_find_by_xpath(): driver.quit() -pytest.mark.skip(reason='the examples are tied to an image with an example, on the site') def find_by_relative_locators(): driver = webdriver.Chrome() driver.get("https://www.selenium.dev/") 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 2a7afc154f73..d09e718e754c 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.en.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.en.md @@ -81,7 +81,7 @@ available in Selenium. driver.findElement(By.className("information")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L9" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -114,7 +114,7 @@ textbox, using css. driver.findElement(By.cssSelector("#fname")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L18" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L17" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -145,7 +145,7 @@ We will identify the Last Name field using it. driver.findElement(By.id("lname")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L26" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L25" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -177,7 +177,7 @@ We will identify the Newsletter checkbox using it. driver.findElement(By.name("newsletter")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L34" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L33" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -207,7 +207,7 @@ In the HTML snippet shared, we have a link available, let's see how will we loca driver.findElement(By.linkText("Selenium Official Page")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L42" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L41" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -238,7 +238,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat driver.findElement(By.partialLinkText("Official Page")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L50" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L49" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -267,7 +267,7 @@ From the above HTML snippet shared, lets identify the link, using its html tag " driver.findElement(By.tagName("a")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L58" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L57" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -302,7 +302,7 @@ first name text box. Let us create locator for female radio button using xpath. driver.findElement(By.xpath("//input[@value='f']")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L66" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L65" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -338,7 +338,7 @@ others it's as simple as setting a parameter in the FindElement function driver.findElement(By.className("information")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L9" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -445,7 +445,7 @@ we can locate the text field element using the fact that it is an "input" elemen By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password")); {{< /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#L73" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); @@ -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#L77" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} {{< /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#L79" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} {{< /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#L81" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} {{< /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#L83" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} {{< /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#L85" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} {{< /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 e0c4567ddc8a..6ea5c5dcd6fc 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.ja.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.ja.md @@ -79,7 +79,7 @@ available in Selenium. driver.findElement(By.className("information")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L9" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -111,7 +111,7 @@ textbox, using css. driver.findElement(By.cssSelector("#fname")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L18" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L17" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -141,7 +141,7 @@ We will identify the Last Name field using it. driver.findElement(By.id("lname")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L26" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L25" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -172,7 +172,7 @@ We will identify the Newsletter checkbox using it. driver.findElement(By.name("newsletter")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L34" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L33" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -201,7 +201,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat driver.findElement(By.linkText("Selenium Official Page")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L42" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L41" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -231,7 +231,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat driver.findElement(By.partialLinkText("Official Page")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L50" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L49" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -259,7 +259,7 @@ From the above HTML snippet shared, lets identify the link, using its html tag " driver.findElement(By.tagName("a")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L58" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L57" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -293,7 +293,7 @@ first name text box. Let us create locator for female radio button using xpath. driver.findElement(By.xpath("//input[@value='f']")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L66" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L65" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -328,7 +328,7 @@ others it's as simple as setting a parameter in the FindElement function driver.findElement(By.className("information")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L9" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -436,7 +436,7 @@ we can locate the text field element using the fact that it is an "input" elemen By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password")); {{< /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#L73" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); @@ -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#L77" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} {{< /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#L79" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} {{< /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#L81" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} {{< /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#L83" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} {{< /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#L85" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} {{< /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 c70bb9e9a2d7..b167bf70ac5f 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 @@ -82,7 +82,7 @@ available in Selenium. driver.findElement(By.className("information")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L9" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -114,7 +114,7 @@ textbox, using css. driver.findElement(By.cssSelector("#fname")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L18" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L17" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -144,7 +144,7 @@ We will identify the Last Name field using it. driver.findElement(By.id("lname")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L26" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L25" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -175,7 +175,7 @@ We will identify the Newsletter checkbox using it. driver.findElement(By.name("newsletter")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L34" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L33" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -204,7 +204,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat driver.findElement(By.linkText("Selenium Official Page")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L42" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L41" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -234,7 +234,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat driver.findElement(By.partialLinkText("Official Page")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L50" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L49" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -262,7 +262,7 @@ From the above HTML snippet shared, lets identify the link, using its html tag " driver.findElement(By.tagName("a")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L58" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L57" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -296,7 +296,7 @@ first name text box. Let us create locator for female radio button using xpath. driver.findElement(By.xpath("//input[@value='f']")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L66" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L65" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -331,7 +331,7 @@ others it's as simple as setting a parameter in the FindElement function driver.findElement(By.className("information")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L9" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -439,7 +439,7 @@ we can locate the text field element using the fact that it is an "input" elemen By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password")); {{< /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#L73" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); @@ -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#L77" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} {{< /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#L79" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} {{< /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#L81" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} {{< /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#L83" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} {{< /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#L85" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} {{< /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 e4a92f1b881a..c395dd916640 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 @@ -82,7 +82,7 @@ available in Selenium. driver.findElement(By.className("information")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L9" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -114,7 +114,7 @@ textbox, using css. driver.findElement(By.cssSelector("#fname")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L18" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L17" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -144,7 +144,7 @@ We will identify the Last Name field using it. driver.findElement(By.id("lname")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L26" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L25" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -175,7 +175,7 @@ We will identify the Newsletter checkbox using it. driver.findElement(By.name("newsletter")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L34" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L33" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -204,7 +204,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat driver.findElement(By.linkText("Selenium Official Page")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L42" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L41" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -234,7 +234,7 @@ In the HTML snippet shared, we have a link available, lets see how will we locat driver.findElement(By.partialLinkText("Official Page")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L50" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L49" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -262,7 +262,7 @@ From the above HTML snippet shared, lets identify the link, using its html tag " driver.findElement(By.tagName("a")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L58" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L57" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -296,7 +296,7 @@ first name text box. Let us create locator for female radio button using xpath. driver.findElement(By.xpath("//input[@value='f']")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L66" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L65" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -331,7 +331,7 @@ others it's as simple as setting a parameter in the FindElement function driver.findElement(By.className("information")); {{< /tab >}} {{< tab header="Python" text=true >}} - {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L10" >}} + {{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L9" >}} {{< /tab >}} {{< tab header="CSharp" >}} var driver = new ChromeDriver(); @@ -439,7 +439,7 @@ we can locate the text field element using the fact that it is an "input" elemen By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password")); {{< /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#L73" >}} {{< /tab >}} {{< tab header="CSharp" >}} var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password")); @@ -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#L77" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}} {{< /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#L79" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}} {{< /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#L81" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}} {{< /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#L83" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}} {{< /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#L85" >}} +{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}} {{< /tab >}} {{< tab header="CSharp" >}} var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel")); From 9ccc041c4c9822a7df88b5304c509578399b178d Mon Sep 17 00:00:00 2001 From: Pablo Martinez Date: Tue, 24 Sep 2024 13:06:50 -0700 Subject: [PATCH 5/5] Update tests per PR suggestion Split the tests for relative locators and used a live page for the tests. --- .../python/tests/elements/test_locators.py | 62 +++++++++++++++---- .../webdriver/elements/locators.en.md | 10 +-- .../webdriver/elements/locators.ja.md | 10 +-- .../webdriver/elements/locators.pt-br.md | 10 +-- .../webdriver/elements/locators.zh-cn.md | 10 +-- 5 files changed, 70 insertions(+), 32 deletions(-) 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"));