diff --git a/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java b/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java index 08f73a7384d6..6e98ce25c6e2 100644 --- a/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java +++ b/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java @@ -1,7 +1,25 @@ package dev.selenium.elements; - +import org.openqa.selenium.By; +import org.openqa.selenium.support.pagefactory.ByChained; import dev.selenium.BaseTest; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; public class LocatorsTest extends BaseTest { + public String ByChainedTest() { + // Create instance of ChromeDriver + WebDriver driver = new ChromeDriver(); + // Navigate to Url + driver.get("https://www.selenium.dev/selenium/web/login.html"); + + // Find username-field inside of login-form + By example = new ByChained(By.id("login-form"), By.id("username-field")); + WebElement username_input = driver.findElement(example); + + //return placeholder text + String placeholder = username_input.getAttribute("placeholder"); + return placeholder; + } } 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 9ad95c1d13cd..3a7751845753 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.en.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.en.md @@ -336,6 +336,8 @@ The FindElement makes using locators a breeze! For most languages, all you need to do is utilize `webdriver.common.by.By`, however in others it's as simple as setting a parameter in the FindElement function +### By + {{< tabpane langEqualsHeader=true >}} {{< badge-examples >}} {{< tab header="Java" >}} @@ -366,6 +368,32 @@ others it's as simple as setting a parameter in the FindElement function {{< /tab >}} {{< /tabpane >}} +### ByChained + +The `ByChained` class enables you to _chain_ two By locators together. For example, instead of having to locate a parent element, and then a child element of that parent, you can instead combine those two `FindElement` functions into one. + +{{< tabpane langEqualsHeader=true >}} +{{< badge-examples >}} + {{< tab header="Java" >}} + {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}} + {{< /tab >}} + {{< tab header="Python" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="Ruby" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="JavaScript" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="Kotlin" text=true >}} + {{< badge-code >}} + {{< /tab >}} +{{< /tabpane >}} + ## Relative Locators **Selenium 4** introduces Relative Locators (previously 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 2510c7d0bbaa..0547c0be8aad 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.ja.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.ja.md @@ -326,6 +326,8 @@ The FindElement makes using locators a breeze! For most languages, all you need to do is utilize `webdriver.common.by.By`, however in others it's as simple as setting a parameter in the FindElement function +### By + {{< tabpane langEqualsHeader=true >}} {{< badge-examples >}} {{< tab header="Java" >}} @@ -356,7 +358,31 @@ others it's as simple as setting a parameter in the FindElement function {{< /tab >}} {{< /tabpane >}} +### ByChained + +The `ByChained` class enables you to _chain_ two By locators together. For example, instead of having to locate a parent element, and then a child element of that parent, you can instead combine those two `FindElement` functions into one. +{{< tabpane langEqualsHeader=true >}} +{{< badge-examples >}} + {{< tab header="Java" >}} + {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}} + {{< /tab >}} + {{< tab header="Python" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="Ruby" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="JavaScript" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="Kotlin" text=true >}} + {{< badge-code >}} + {{< /tab >}} +{{< /tabpane >}} ## 相対ロケーター 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 bef40f0290f0..f8c851b386ab 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 @@ -329,6 +329,8 @@ The FindElement makes using locators a breeze! For most languages, all you need to do is utilize `webdriver.common.by.By`, however in others it's as simple as setting a parameter in the FindElement function +### By + {{< tabpane langEqualsHeader=true >}} {{< badge-examples >}} {{< tab header="Java" >}} @@ -359,6 +361,32 @@ others it's as simple as setting a parameter in the FindElement function {{< /tab >}} {{< /tabpane >}} +### ByChained + +The `ByChained` class enables you to _chain_ two By locators together. For example, instead of having to locate a parent element, and then a child element of that parent, you can instead combine those two `FindElement` functions into one. + +{{< tabpane langEqualsHeader=true >}} +{{< badge-examples >}} + {{< tab header="Java" >}} + {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}} + {{< /tab >}} + {{< tab header="Python" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="Ruby" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="JavaScript" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="Kotlin" text=true >}} + {{< badge-code >}} + {{< /tab >}} +{{< /tabpane >}} + ## Relative Locators **Selenium 4** introduces Relative Locators (previously 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 b7891592f87b..e1cc00eacf53 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 @@ -329,6 +329,8 @@ The FindElement makes using locators a breeze! For most languages, all you need to do is utilize `webdriver.common.by.By`, however in others it's as simple as setting a parameter in the FindElement function +### By + {{< tabpane langEqualsHeader=true >}} {{< badge-examples >}} {{< tab header="Java" >}} @@ -359,6 +361,32 @@ others it's as simple as setting a parameter in the FindElement function {{< /tab >}} {{< /tabpane >}} +### ByChained + +The `ByChained` class enables you to _chain_ two By locators together. For example, instead of having to locate a parent element, and then a child element of that parent, you can instead combine those two `FindElement` functions into one. + +{{< tabpane langEqualsHeader=true >}} +{{< badge-examples >}} + {{< tab header="Java" >}} + {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#17-19" >}} + {{< /tab >}} + {{< tab header="Python" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="CSharp" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="Ruby" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="JavaScript" text=true >}} + {{< badge-code >}} + {{< /tab >}} + {{< tab header="Kotlin" text=true >}} + {{< badge-code >}} + {{< /tab >}} +{{< /tabpane >}} + ## Relative Locators **Selenium 4** introduces Relative Locators (previously