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 6e98ce25c6e2..bcc473f7a8be 100644 --- a/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java +++ b/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java @@ -1,13 +1,32 @@ package dev.selenium.elements; import org.openqa.selenium.By; +import org.openqa.selenium.support.pagefactory.ByAll; import org.openqa.selenium.support.pagefactory.ByChained; import dev.selenium.BaseTest; +import java.util.List; + import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class LocatorsTest extends BaseTest { + + public void ByAllTest() { + // Create instance of ChromeDriver + WebDriver driver = new ChromeDriver(); + // Navigate to Url + driver.get("https://www.selenium.dev/selenium/web/login.html"); + + // get both logins + By example = new ByAll(By.id("password-field"), By.id("username-field")); + List login_inputs = driver.findElements(example); + + //send them both input + login_inputs.get(0).sendKeys("username"); + login_inputs.get(1).sendKeys("password"); + } + public String ByChainedTest() { // Create instance of ChromeDriver WebDriver driver = new ChromeDriver(); 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 3a7751845753..d08963fd063d 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.en.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.en.md @@ -370,12 +370,39 @@ others it's as simple as setting a parameter in the FindElement function ### 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. +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 header="Java" text=true >}} + {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#L37-L38">}} + {{< /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 >}} + +### ByAll + +The `ByAll` class enables you to utilize two By locators at once, finding elements that mach _either_ of your By locators. +For example, instead of having to utilize two `FindElement()` functions to find the username and password input fields +seperately, you can instead find them together in one clean `FindElements()` + +{{< tabpane langEqualsHeader=true >}} + {{< tab header="Java" text=true >}} + {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#L22-L23">}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< badge-code >}} 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 0547c0be8aad..28b11bcd66cc 100644 --- a/website_and_docs/content/documentation/webdriver/elements/locators.ja.md +++ b/website_and_docs/content/documentation/webdriver/elements/locators.ja.md @@ -360,12 +360,40 @@ others it's as simple as setting a parameter in the FindElement function ### 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. +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 header="Java" text=true >}} + {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#L37-L38" >}} + {{< /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 >}} + +### ByAll + +The `ByAll` class enables you to utilize two By locators at once, finding elements that mach _either_ of your By locators. +For example, instead of having to utilize two `FindElement()` functions to find the username and password input fields seperately, +you can instead find them together in one clean `FindElements()` + +{{< tabpane langEqualsHeader=true >}} + {{< tab header="Java" text=true >}} + {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#L22-L23">}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< badge-code >}} 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 f8c851b386ab..de57a4812d37 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 @@ -363,12 +363,40 @@ others it's as simple as setting a parameter in the FindElement function ### 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. +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 header="Java" text=true >}} + {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#L37-L38" >}} + {{< /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 >}} + +### ByAll + +The `ByAll` class enables you to utilize two By locators at once, finding elements that mach _either_ of your By locators. +For example, instead of having to utilize two `FindElement()` functions to find the username and password input fields +seperately, you can instead find them together in one clean `FindElements()` + +{{< tabpane langEqualsHeader=true >}} + {{< tab header="Java" text=true >}} + {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#L22-L23">}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< badge-code >}} 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 e1cc00eacf53..b8e38f81faff 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 @@ -363,12 +363,40 @@ others it's as simple as setting a parameter in the FindElement function ### 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. +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 header="Java" text=true >}} + {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#L37-L38" >}} + {{< /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 >}} + +### ByAll + +The `ByAll` class enables you to utilize two By locators at once, finding elements that mach _either_ of your By locators. +For example, instead of having to utilize two `FindElement()` functions to find the username and password input fields +seperately, you can instead find them together in one clean `FindElements()` + +{{< tabpane langEqualsHeader=true >}} + {{< tab header="Java" text=true >}} + {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java#L22-L23">}} {{< /tab >}} {{< tab header="Python" text=true >}} {{< badge-code >}}